首页 > 其他分享 >toFixed ()保留两位小数

toFixed ()保留两位小数

时间:2022-11-29 20:47:56浏览次数:36  
标签:两位 console log 保留 num toFixed 小数

toFixed()用于保留两位小数

 

<body>
    <script>
      // toFixed(指定保留小数的个数) 方法可以让数字指定保留的小数位数 会进行四舍五入
      const num = 3.1415926778899;
      console.log(num.toFixed(2)); //保留2位小数
      console.log(num.toFixed(1)); //保留1位小数
      console.log(num.toFixed(0)); //保留0位小数
      console.log(num.toFixed(-1)); //会报错
    </script>
  </body>

 

标签:两位,console,log,保留,num,toFixed,小数
From: https://www.cnblogs.com/JAG2671169285/p/16936595.html

相关文章