How do I convert an integer to a float in JavaScript?

What you have is already a floating point number, they’re all 64-bit floating point numbers in JavaScript.

To get decimal places when rendering it (as a string, for output), use .toFixed(), like this:

function intToFloat(num, decPlaces) { return num.toFixed(decPlaces); }

You can test it out here (though I’d rename the function, given it’s not an accurate description).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)