简体   繁体   中英

Javascript round number after the . to 3 digits only

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?

You can use the toFixed method

 const number = 14.4565576 console.log(number.toFixed(3))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM