convert decimal number to fraction in javascript or closest fraction

后端 未结 10 1582
温柔的废话
温柔的废话 2020-12-05 16:12

So i want to be able to convert any decimal number into fraction. In both forms such as one without remainder like this: 3/5 or with remainder: 3 1/4

10条回答
  •  隐瞒了意图╮
    2020-12-05 16:43

    Unless you are willing to work on developing something yourself then I would suggest using a library that someone has already put effort into, like fraction.js

    Javascript

    var frac = new Fraction(0.3435);
    
    console.log(frac.toString());
    

    Output

    687/2000
    

    On jsFiddle

提交回复
热议问题