javascript - Round decimal place only to 3 places -
i need round decimal places three:
here code:
var split_arr = subtotal_string.split(".", subtotal_string); var integer = split_arr[0]; var decimal = split_arr[1]; var decimal_new = decimal.tofixed(3);
but not working..
please help, thanks
you don't need split it, cast string number (+
) call tofixed()
:
var threedp = (+subtotal_string).tofixed(3); // 9.43663436 -> 9.437
Comments
Post a Comment