Here's the relevant code. I've confirmed with the alert that the correct number is saved, it's just not being changed to 2 decimal places.
if ($(this).attr('name') == 'time') { var value = $(this).val(); parseFloat(value).toFixed(2); alert(value); editEntry.time = value; }
html. The toFixed() method in JavaScript is used to format a number using fixed-point notation. It can be used to format a number with a specific number of digits to the right of the decimal. The toFixed() method is used with a number as shown in above syntax using the '.
Description. toFixed() returns a string representation of numObj that does not use exponential notation and has exactly digits digits after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length.
Note. The toFixed() method will round the resulting value if necessary. The toFixed() method will pad the resulting value with 0's if there are not enough decimal places in the original number. The toFixed() method does not change the value of the original number.
The Math. round() method rounds a number to the nearest integer. 2.49 will be rounded down (2), and 2.5 will be rounded up (3).
You're not assigning the parsed float back to your value var:
value = parseFloat(value).toFixed(2);
should fix things up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With