How to round this value "1153.7759999999999" to 1153.78 dynamically
Asked
Active
Viewed 89 times
-5
-
`Number("1153.7759999999999").toFixed(2)` – Pranav C Balan Jun 13 '16 at 10:59
-
`var num = parseInt("1153.7759999999999"); var n = num.toFixed(2); ` – Insane Skull Jun 13 '16 at 11:03
-
note that using .toFixed() will yield a string of the nominated length - you will need to reparse it as a number if you want to do calculations on it after rounding it. – gavgrif Jun 13 '16 at 11:32
-
Possible duplicate of [Formatting a number with exactly two decimals in JavaScript](http://stackoverflow.com/questions/1726630/formatting-a-number-with-exactly-two-decimals-in-javascript) – Wai Ha Lee Jun 13 '16 at 16:10
2 Answers
0
You are looking for .toFixed(2)
var num = 1153.7759999999999;
console.log(num.toFixed(2));

Sudharsan S
- 15,336
- 3
- 31
- 49