0

I am trying to convert a decimal number into a fractional one. As I already know, there is no direct inbuilt function in JS to do it, so I have come with those steps as a logic:

Step 1 - Find out the number of digits after the decimal point, let's call it Q
Step 2 - Multiply the Numerator and Denominator by 10 with the exponent of Q
Step 3 - Find the greatest common divisor for Numerator and Denominator
Step 4 - Divide the Numerator and Denominator by that greatest common divisor separately

I am now trying to find a way to figure out the number of digits after the decimal point.

I would appreciate your help here if someone can assist to figure this out fully as I am very new to JS and development itself.

Thanks

370147
  • 57
  • 5
  • JavaScript numbers are represented with **binary** floating-point. There are therefore *no* "decimal places", internally; they're "binary places". – Pointy May 05 '20 at 17:05
  • There is also [Convert a decimal number to a fraction / rational number](https://stackoverflow.com/q/14783869/218196) – Felix Kling May 05 '20 at 17:09

0 Answers0