I would like to format my numbers to always display 2 decimal places, rounding where applicable.
Examples:
number display
------ -------
1 1.00
1.341 1.34
1.345 1.35
I have been using this:
parseFloat(num).toFixed(2);
But it's displaying 1
as 1
, rather than 1.00
.
here is another solution to round only using floor, meaning , making sure calculated amount won't be bigger than original amount (sometimes needed for transactions): Math.floor(num* 100 )/100
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
Are you looking for floor?
Here's also a generic function that can format to any number of decimal places: