JavaScript Number toExponential()

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

推荐阅读

你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战