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
热门推荐
5 短祝福语简短暖心
10 结婚祝福语粤语大全简短
11 晚上祝福语女生文案简短
12 法语妈妈生日祝福语简短
13 药厂开工祝福语大全简短
14 蛋糕节日祝福语简短英文
15 跨年的生日祝福语简短
16 文案祝福语英文短句简短
17 在家聚餐婚礼祝福语简短
18 学生节祝福语大全简短