簡體   English   中英

防止toFixed舍入非常小的十進制數

[英]Prevent toFixed from rounding off very small decimal numbers

我的值非常小,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

請有人建議我一個解決方案

(0.09986684420772304).toPrecision(3)

Math.floor(0.09986684420772304 * 10000) / 10000

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM