JavaScript 中的 Number.toFixed() 函数
htmljavascriptprogramming scripts更新于 2024/10/13 10:20:17
Number 对象的 toFixed() 函数接受一个表示小数点后要显示的点数的数字,并据此显示当前数字。
语法
其语法如下
num.toFixed(num);
示例
<html>
<head>
<title>JavaScript 示例</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
result = num.toFixed(4);
document.write("给定数字的定点表示法为:" + result);
</script>
</body>
</html>
输出
给定数字的定点表示法为:3.1416
示例
<html>
<head>
<title>JavaScript 示例</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
document.write("给定数字的定点表示法为: " + num.toFixed(4));
document.write("<br>");
var num = 2.13e+15;
document.write("给定数字的定点表示法为: " + num.toFixed(4));
</script>
</body>
</html>
输出
给定数字的定点表示法为:3.1416 给定数字的定点表示法为:2130000000000000.0000
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

