【问题标题】:Round off nearest Value in jquery?在jquery中舍入最近的值?
【发布时间】:2020-03-11 06:37:30
【问题描述】:

我需要将浮点值四舍五入为最接近的整数,例如如果值是

2.4 = 2

如果我的价值是

2.5 = 3

我使用了 round()、floor() 和 toFixed() 但它只做了向上、向下、相等的数字。

【问题讨论】:

  • “需要一个等效的 jQuery 函数”是什么意思? jQuery 是 JavaScript。你能告诉我们你想做什么吗?

标签: javascript jquery


【解决方案1】:

你只需要 JavaScript 的 Math.round 方法:

console.log(Math.round(2.4));

console.log(Math.round(2.5));

【讨论】:

  • 我需要在我的函数中的 jquery 上使用它 我试过像 $(document).ready(function(){ $("button").click(function(){ var h = Math .round(2.4); 警报(h); }); });它显示下一个整数
  • @JeyakumarKumar 你确定吗? :)
猜你喜欢
  • 2018-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-22
  • 2013-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多