防止toFixed舍入非常小的十进制数

时间:2018-10-18 14:05:58

标签: javascript tofixed

我的值非常小,0.09986684420772304,我想显示最多三位小数。 toFixed将其四舍五入。

(0.09986684420772304).toFixed(3) ==> 0.100

我什至尝试

(Math.round(0.09986684420772304 * 100)/100).toFixed(3) => 0.100  

我需要的是

(0.09986684420772304).toFixed(3) ==> 0.0998

请有人给我建议解决方案

1 个答案:

答案 0 :(得分:2)

(0.09986684420772304).toPrecision(3)

Math.floor(0.09986684420772304 * 10000) / 10000

相关问题