I have a float number like 137.57667565656 but I would like to round it such that there are only two trailing digits after the decimal point like the new float number will be 137.58.
I tried this so far:
What did you expect?
simply returns the original value of value, so
is identical to:
you then have:
so value is rounded to an integer, toFixed will add two decimal places and return a string so the toString part is redundant. If you wish to round value to four decimal places, then:
will do the job:
var x = 137.57667565656; console.log(x.toFixed(4)); // 137.5767
If you want to round it to 2 places but present it as 4, then:
Number(x.toFixed(2)).toFixed(4) // 137.5800