1.定义

toFixed() 方法可把 Number 四舍五入为指定小数位数的数字。

 

2.示例

Show the number 13.37 with one decimal:
<script type="text/javascript">
    var num = new Number(13.37);
    document.write (num.toFixed(1))
</script>

 

Show the number 13.37 with one decimal:
13.4

 

3.注意事项

NumberObject.toFixed(num)
参数    描述
num    必需。规定小数的位数,是 0 ~ 20 之间的值,包括 0 和 20,有些实现可以支持更大的数值范围。如果省略了该参数,将用 0 代替。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-06-08
  • 2021-08-29
  • 2021-10-01
相关资源
相似解决方案