How to get floating Number?


Hello, campers. I’m struggling to get floating Number from integer Number. I’d like to get something like this 5 -> 5.00. Tried to use toFixed(), but it returns string. Thank for spending you time.
(5).toFixed(2) // return string "5.00"
parseFloat((5).toFixed(2)) // return Number 5
Number((5).toFixed(2)) // return Number 5

// first you'll have to convert your integer to number, you want to make sure you're dealing with a number

var toNum = Number(value);
return toNum.toFixed(2); // 2 is the number of decimal places

that should work

Hope it will be helpful :slight_smile:


Numbers in JS are floating-point to begin with.


JS doesn’t have such a function.


this is not good expression;

// first cast your value to number format, before you do convert it float i.e: Number(5).toFixed(2);



It doesn’t work though.