javascriptmath

How to round up to the nearest 100 in JavaScript


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

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


Solution

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

    Math.ceil(number/100)*100