1

How can I round in javascript from 69.85 to 69.9. When I use .toFixed(1) it gives me 69.8 instead of 69.9.

Please refer below:

Not rounding graph label

Ramiz Wachtler
  • 5,623
  • 2
  • 28
  • 33
  • 3
    Known issue with `toFixed`... multiply by power of 10, round, divide back... – iAmOren Jul 09 '20 at 08:04
  • 1
    Hi! Welcome to Stack Overflow. To help you further, could you please add some existing code to your question? – Chris Jul 09 '20 at 08:05
  • Voting to close as dupe – Always Helping Jul 09 '20 at 08:12
  • Maybe try [Math.round()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round), Also, if you're working with floating point numbers (which i believe is the default unless you typecast them), you'll want to round them before operating on them. [here's a good explanation](https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript) – admcfajn Jul 09 '20 at 08:13

0 Answers0