Why is my toFixed() function not working? Why is my toFixed() function not working? jquery jquery

Why is my toFixed() function not working?


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

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

should fix things up.


I tried function toFixed(2) many times. Every time console shows "toFixed() is not a function".

but how I resolved is By using Math.round()

eg:

if ($(this).attr('name') == 'time') {    var value = parseFloat($(this).val());    value = Math.round(value*100)/100; // 10 defines 1 decimals, 100 for 2, 1000 for 3    alert(value);}

this thing surely works for me and it might help you guys too...


Example simple (worked):

var a=Number.parseFloat($("#budget_project").val()); // from input fieldvar b=Number.parseFloat(html); // from ajaxvar c=a-b;$("#result").html(c.toFixed(2)); // put to id='result' (div or others)