Number to fractional number

Hi all

I have one number. I want to convert that it to fractional

For ex: I have a=0.02 so if I convert that number into fraction then it will be 1:50

So I dont want to express it in fractional feet and inches I want express it in SI fractional unit. Please let me know how to convert a number into fraction (SI fraction i.e 1:ratio) like explained above.

@shashank.baganeACM I do not think you can get it other than a string, maybe someone else can prove me wrong:


Looks like there’s a module for converting decimals to a numerator and denominator, but otherwise I believe @tradelie is correct. There’s no fractional number type so the best you can do is a string. This also allows you to round to a fractional precision if the decimal is irrational or otherwise results in an “awkward” fraction.


Thank you so much @tradelie

1 Like

and if I want reverse output

I mean if I have a string 1:50 and if I want to get number 0.02 then how to do that ? Can you please tell me

@shashank.baganeACM maybe something like this:


Thank you @tradelie

1 Like