[英]How do I format a number in scientific notation to show less digits in Javascript?
For example, I have a number which is 1.3685999999999998e+35 but I just want to display 1.368e+35. 例如,我有一个数字1.3685999999999998e + 35,但我只想显示1.368e + 35。 I tried toFixed and toPrecision but nothing works.
我尝试固定和精确,但没有任何效果。
You need to use Number.prototype.toExponential
: 您需要使用
Number.prototype.toExponential
:
var x = 11827361827361872361263812631827361823618723; console.log(x.toExponential(2)); console.log(x.toExponential(3)); console.log(x.toExponential(10));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.