![](/img/trans.png)
[英]how to round up and keep number of digits after decimal point in javascript
[英]How to truncate (not round) a particular number after decimal point using javascript
輸入:-81.82637799999999(小數點后14位)
輸出:-81.8263779999999(小數點后13位)
我如何使用 javascript 來實現它?
試試這個。 看看它是否適合你
var x = -81.82637799999999;
x = x.toString(); // convert to string
alert(x.length);
x = x.substring(0, x.length - 1); // cut out last character
alert(x.length);
x = parseFloat(x); // convert it back to float
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.