Javascript 中的 toExponential()函数

首页 / JavaScript入门教程 / Javascript 中的 toExponential()函数

此方法返回以指数表示法表示number对象的字符串。

toExponential() - 语法

number.toExponential( [fractionDigits] )

fractionDigits  -  一个整数,指定小数点后的位数。

无涯教程网

toExponential() - 返回值

以指数表示法表示数字对象的字符串,小数点前有一位数,小数点后舍入为fractionDigits位数。

链接:https://www.learnfk.comhttps://www.learnfk.com/javascript/number-toexponential.html

来源:LearnFk无涯教程网

toExponential() - 示例

<html>
   <head>
      <title>Javascript Method toExponential()</title>
   </head>
   
   <body>
      <script type="text/javascript">
         var num=77.1234;
         var val=num.toExponential(); 
         document.write("num.toExponential() is : " + val );
         document.write("<br />"); 
         
         val=num.toExponential(4);
         document.write("num.toExponential(4) is : " + val );
         document.write("<br />"); 
         
         val=num.toExponential(2); 
         document.write("num.toExponential(2) is : " + val); 
         document.write("<br />"); 
         
         val=77.1234.toExponential(); 
         document.write("77.1234.toExponential()is : " + val ); 
         document.write("<br />"); 
         
         val=77.1234.toExponential(); 
         document.write("77 .toExponential() is : " + val); 
      </script>   
   </body>
</html>

运行上面代码输出

num.toExponential() is : 7.71234e+1
num.toExponential(4) is : 7.7123e+1
num.toExponential(2) is : 7.71e+1
77.1234.toExponential()is:7.71234e+1
77 .toExponential() is : 7.71234e+1

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Nginx核心知识150讲 -〔陶辉〕

TensorFlow快速入门与实战 -〔彭靖田〕

大规模数据处理实战 -〔蔡元楠〕

数据中台实战课 -〔郭忆〕

视觉笔记入门课 -〔高伟〕

编译原理实战课 -〔宫文学〕

爆款文案修炼手册 -〔乐剑峰〕

React Hooks 核心原理与实战 -〔王沛〕

大厂广告产品心法 -〔郭谊〕

好记忆不如烂笔头。留下您的足迹吧 :)