源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>toExponential()方法返回一个字符串,该字符串使用指数符号舍入和写入.</p> <p>可选参数定义小数点后面的位数.</p> <p id="demo"></p> <script> var x = 9.656; document.getElementById("demo").innerHTML = x.toExponential() + "<br>" + x.toExponential(2) + "<br>" + x.toExponential(4) + "<br>" + x.toExponential(6); </script> </body> </html>
运行结果