简体   繁体   English

如何用科学计数法格式化数字以在Javascript中显示更少的数字?

[英]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.

相关问题 如何将包含科学记数法的字符串转换为正确的 Javascript 数字格式 - How to convert a String containing Scientific Notation to correct Javascript number format 我们如何将Javascript中的科学计数法转换为数字 - How do we convert scientific notation to number in Javascript javascript 转换科学计数法,如何确定 10 次方后的数字 - javascript converting scientific notation, how to determine the number after power of 10 如果不用科学记数法显示,JavaScript编号有多小? - How small can a JavaScript number be without displaying in scientific notation? Javascript - 科学记数法受限制的最大数量是多少? - Javascript - What is the maximum number in scientific notation restricted by? 科学符号手机号码-Excel Javascript - Scientific notation mobile number - Excel Javascript 如何将 JavaScript BigInt 值转换为科学记数法? - How can I convert a JavaScript BigInt value to Scientific Notation? 如何在javascript中将大的负科学记数字转换为十进制记号字符串? - How to convert big negative scientific notation number into decimal notation string in javascript? 如何将数字四舍五入为 JavaScript 中的多个有效前导数字? - How do I round a number to a number of significant leading digits in JavaScript? 如何避免 JavaScript 中大数的科学记数法? - How to avoid scientific notation for large numbers in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM