Convert a decimal number to a fraction / rational number

前端 未结 11 1823
情歌与酒
情歌与酒 2020-12-01 16:36

In JavaScript, is there any way to convert a decimal number (such as 0.0002) to a fraction represented as a string (such as \"2/10000\")?

I

11条回答
  •  天命终不由人
    2020-12-01 17:09

    I just want a leave one alternative that I found to convert decimal numbers into fractions and reducing fractions, it's a JS library.

    The library calls fraction.js, it was really helpful for me and save me a lot time and work. Hope can be useful to somebody else!

提交回复
热议问题