javascript convert int to float

前端 未结 2 1883
情话喂你
情话喂你 2020-12-08 01:52

I have a variable

var fval = 4;

now I want out put as 4.00

相关标签:
2条回答
  • 2020-12-08 02:07

    toFixed() method formats a number using fixed-point notation. Read MDN Web Docs for full reference.

    var fval = 4;
    
    console.log(fval.toFixed(2)); // prints 4.00
    
    0 讨论(0)
  • 2020-12-08 02:15

    JavaScript only has a Number type that stores floating point values.

    There is no int.

    Edit:

    If you want to format the number as a string with two digits after the decimal point use:

    (4).toFixed(2)
    
    0 讨论(0)
提交回复
热议问题