Why is my toFixed() function not working?

Ben picture Ben · Feb 8, 2011 · Viewed 120.2k times · Source

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;
}

Answer

Marc B picture Marc B · Feb 8, 2011

You're not assigning the parsed float back to your value var:

value = parseFloat(value).toFixed(2);

should fix things up.