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:
(Math.round((value*100)/100)).toFixed(2).toString();
But unfortunately, it rounds my value to 137.00. It adds the decimals places as zeroes, why?
How can I achieve the above?
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:
If you want to round it to 2 places but present it as 4, then: