JavaScript中的Number.toFixed()函数
toFixed()Number对象的功能接受一个数字,该数字表示要在小数点后显示的点数,并相应地显示当前数字。
语法
其语法如下
num.toFixed(num);
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
result = num.toFixed(4);
document.write("Fixed point notation of the given number is: " + result);
</script>
</body>
</html>输出结果
Fixed point notation of the given number is: 3.1416
示例
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<script type="text/javascript">
var num = Math.PI;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
document.write("<br>");
var num = 2.13e+15;
document.write("Fixed point notation of the given number is: " + num.toFixed(4));
</script>
</body>
</html>输出结果
Fixed point notation of the given number is: 3.1416 Fixed point notation of the given number is: 2130000000000000.0000
热门推荐
6 薛之谦祝福语简短
10 对睡觉的祝福语简短
11 科研文案祝福语简短励志
12 单位搬迁新址祝福语简短
13 新婚红包祝福语简短男
14 毕业祝福语简短给同学
15 新婚快乐所有祝福语简短
16 好友上岸成功祝福语简短
17 给儿子生日祝福语 简短
18 高中升学宴祝福语简短