javascript convert int to float

Javascript

Javascript Problem Overview


I have a variable

var fval = 4;

now I want out put as 4.00

Javascript Solutions


Solution 1 - Javascript

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)

Solution 2 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRajeshView Question on Stackoverflow
Solution 1 - JavascriptAlex JasminView Answer on Stackoverflow
Solution 2 - JavascriptnkshioView Answer on Stackoverflow