如何在JavaScript中四舍五入到最接近的100 [英] How to round up to the nearest 100 in JavaScript

查看:75
本文介绍了如何在JavaScript中四舍五入到最接近的100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论值是101还是199,我都想一直舍入到 nearest 100,例如,应该舍入到200.例如:

I want to round up to the nearest 100 all the time whether or not the value is 101 or 199 it should round up to 200. For example:

var number = 1233;
//use something like Math.round() to round up to always 1300

我想始终使用jQuery舍入到最接近的100,而不舍入.

I'd like to always round up to the nearest 100, never round down, using jQuery.

推荐答案

如果要始终取整,请使用Math.ceil():

Use Math.ceil(), if you want to always round up:

Math.ceil(number/100)*100

这篇关于如何在JavaScript中四舍五入到最接近的100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆