toExponential()
方法的语法是
num.toExponential(fractionDigits)
这里,num
是一个数字。
Number toExponential() 参数
toExponential()
方法接受
- fractionDigits (可选) - 一个整数,指定小数点后有多少位数字。默认情况下,它会尽可能多地显示指定数字所需的位数。
Number toExponential() 的返回值
- 返回一个字符串,表示给定的
Number
对象以科学计数法表示,并四舍五入到小数点后fractionDigits
位。
示例:使用 Number.toExponential()
let num = 695.8457;
let exp_num = num.toExponential();
console.log(exp_num); // 6.958457e+2
let exp_num1 = num.toExponential(2);
console.log(exp_num1); // 6.96e+2
输出
6.958457e+2 6.96e+2
推荐阅读