Convert Fraction String to Decimal?

前端 未结 16 663
谎友^
谎友^ 2020-12-05 13:55

I\'m trying to create a javascript function that can take a fraction input string such as \'3/2\' and convert it to decimal—either as a string \'1.5\'

16条回答
  •  没有蜡笔的小新
    2020-12-05 14:38

    To convert a fraction to a decimal, just divide the top number by the bottom number. 5 divided by 3 would be 5/3 or 1.67. Much like:

    function decimal(top,bottom) {
        return (top/bottom)
    }
    

    Hope this helps, haha

提交回复
热议问题