【问题标题】:How to round a floating value to its closest integer in Jquery如何在 Jquery 中将浮点值舍入为其最接近的整数
【发布时间】:2014-04-04 10:18:48
【问题描述】:

我想将130.68(大于或等于130.5)和131.32(小于131.5)值四舍五入为131

【问题讨论】:

标签: jquery floating-point int rounding


【解决方案1】:

使用Math.round()

Math.round(130.68); // return 131
Math.round(131.32); // return 131

Fiddle Demo

【讨论】:

    【解决方案2】:

    您需要使用Math.round(),在下面的示例中,两个语句都会提醒131

    alert(Math.round(130.68));
    alert(Math.round(131.32));
    

    DEMO

    【讨论】:

      【解决方案3】:

      你可以使用 Math.round

      num=130.68; 
      Math.round(num);
      

      【讨论】:

        【解决方案4】:

        使用此链接:

        Use Math.round()

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-09-27
          • 1970-01-01
          • 2013-06-13
          • 2018-07-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多