javascriptjquerynumber-formatting

Why is my toFixed() function not working?


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

Solution

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

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

    should fix things up.