当前位置:嗨网首页>书籍在线阅读

04-指数符号

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

16.1.2 指数符号

如果希望用指数形式来显示数字,可以用:Number.prototype.toExponential:

const x = 3800.5;
x.toExponential(4);         // "3.8005e+4";
x.toExponential(3);         // "3.801e+4";
x.toExponential(2);         // "3.80e+4";
x.toExponential(1);         // "3.8e+4";
x.toExponential(0);         // "4e+4";

Number.prototype.toFixed 一样,结果也是四舍五入的。指定的精度是小数位的个数。