![](/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.