-1

I have a variable with a result that looks like this:

myresult = 14.4565576

I need to round the decimal after the DOT to only 3 numbers.

For example I need to round this:

14.4565576

to this:

14.456

How can I do this?

keszok
  • 67
  • 5
  • 1
    ```myresult.toFixed(3)``` – user Jun 09 '22 at 12:38
  • The proposed answer for `1.2` will give you `1.200`, not sure if that's what you want. I don't think you've made too much research btw, check this threat for example: https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary – pbialy Jun 09 '22 at 12:41
  • Does this answer your question? [How to round to at most 2 decimal places, if necessary](https://stackoverflow.com/questions/11832914/how-to-round-to-at-most-2-decimal-places-if-necessary) – aca Jun 09 '22 at 12:42

1 Answers1

0

You can use the toFixed method

const number = 14.4565576
console.log(number.toFixed(3))
RenaudC5
  • 3,553
  • 1
  • 11
  • 29