简体   繁体   English

后的 Javascript 整数。 仅限 3 位数

[英]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.我需要将 DOT 后的小数点四舍五入到只有 3 个数字。

For example I need to round this:例如我需要四舍五入:

14.4565576

to this:对此:

14.456

How can I do this?我怎样才能做到这一点?

You can use the toFixed method您可以使用toFixed方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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