Javascript number placing and how to , 4 = 0.04, 14 = 0.14, 100 = 1.00

后端 未结 2 337
悲哀的现实
悲哀的现实 2021-01-29 14:34

I am trying to write a custom calculator but I am having trouble trying to work out a figure, I want to be able to add decimal points before the number which has been in puted.<

相关标签:
2条回答
  • 2021-01-29 14:54

    How about this?

    var num = 4; var fig = num * 0.01;
    
    0 讨论(0)
  • 2021-01-29 15:14
    >>> [4, 14, 100].map(function(n) { return (n / 100).toFixed(2) })
    ["0.04", "0.14", "1.00"]
    
    0 讨论(0)
提交回复
热议问题