🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › ceil
Math.ceil() - JavaScript | MDN - Mozilla
Math.ceil(-Infinity); // -Infinity Math.ceil(-7.004); // -7 Math.ceil(-4); // -4 Math.ceil(-0.95); // -0 Math.ceil(-0); // -0 Math.ceil(0); // 0 Math.ceil(0.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8 Math.ceil(Infinity); // Infinity ... This page was last modified on Jul 10, 2025 by ...
🌐
WebPlatform
webplatform.github.io › docs › javascript › Math › ceil
ceil · WebPlatform Docs
javascript · Math · ceil · Returns the smallest integer greater than or equal to its numeric argument. Math.ceil( number ) Math.ceil(0.4); // 1 Math.ceil(1.9); // 2 Math.ceil(3); // 3 · The required number argument is a numeric expression. The return value is an integer value equal to the ...
Discussions

node.js - Is there a condition where the Math.ceil function in Javascript doesn't remove decimals from the output? - Stack Overflow
Is there a condition where the Math.ceil() function in Javascript doesn't remove decimals from the output? More on stackoverflow.com
🌐 stackoverflow.com
javascript - Math.round vs. math.ceil yields unexpected results - Stack Overflow
The user may input a value or a simple expression as a division. The output should be a value to 2 decimal places. e.g. 8.50 should yield 8.50 4/2 should yield 2.00 But if the input is a division More on stackoverflow.com
🌐 stackoverflow.com
November 11, 2022
math - javascript - ceiling of a dollar amount - Stack Overflow
So I am adding and subtracting floats in javascript, and I need to know how to always take the ceiling of any number that has more than 3 decimal places. For example: 3.19 = 3.19 3.191 = 3.20 3. More on stackoverflow.com
🌐 stackoverflow.com
Why not always use Math.round instead of Math.floor?

Well, they are two different functions, with two different uses. Math.floor() always rounds down to the nearest integer, while Math.round() will round up or down depending on what side of .5 the number falls on. So, the basic answer is that you use which one gets the result you expect.

When it comes to generating random numbers though, Math.floor() has a more even distribution than Math.round(). If you want to generate a random number between 0 and 2, take the following examples:

Math.floor(Math.random() * 3). Here, 0-0.999999 will give you 0, 1.0 to 1.999999 will give you 1, and 2.0 to 2.999999 will give you 2. Every number has a 33% chance of being the result.

Math.round(Math.random() * 2). Here, 0-0.499999 will give you 0, 0.5 to 1.499999 will give you 1, and 1.5 to 1.999999 will give you 2. Note that the range of numbers that lead to a 1 is twice as big as those that lead to 0 or 1. That is 25% chance of 0, 50% chance of 1, and 25% chance of 2.

More on reddit.com
🌐 r/javascript
13
1
February 22, 2017
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › global_objects › math › ceil › index.md
content/files/en-us/web/javascript/reference/global_objects/math/ceil/index.md at main · mdn/content
The **`Math.ceil()`** static method always rounds up and returns the smallest integer greater than or equal to a given number. ... The smallest integer greater than or equal to `x`. It's the same value as [`-Math.floor(-x)`](/en-US/docs/Web...
Author   mdn
🌐
W3Schools
w3schools.com › jsref › jsref_ceil.asp
JavaScript Math ceil() Method
new Map clear() delete() entries() forEach() get() groupBy() has() keys() set() size values() JS Math · abs() acos() acosh() asin() asinh() atan() atan2() atanh() cbrt() ceil() clz32() cos() cosh() E exp() expm1() f16round() floor() fround() LN2 LN10 log() log10() log1p() log2() LOG2E LOG10E max() min() PI pow() random() round() sign() sin() sinh() sqrt() SQRT1_2 SQRT2 tan() tanh() trunc() JS Numbers
🌐
Math.js
mathjs.org › docs › reference › functions › ceil.html
math.js | an extensive math library for JavaScript and Node.js
math.ceil(3.2) // returns number 4 math.ceil(3.8) // returns number 4 math.ceil(-4.2) // returns number -4 math.ceil(-4.7) // returns number -4 math.ceil(3.212, 2) // returns number 3.22 math.ceil(3.288, 2) // returns number 3.29 math.ceil(-4.212, 2) // returns number -4.21 math.ceil(-4.782, ...
🌐
Programiz
programiz.com › javascript › library › math › ceil
JavaScript Math ceil()
Become a certified JavaScript programmer. Try Programiz PRO! ... The ceil() method rounds a decimal number up to the next largest integer and returns it. That is, 4.3 will be rounded to 5 (next largest integer). let number = Math.ceil(4.3); console.log(number); // Output: 5
🌐
GitHub
gist.github.com › vpodk › c2ad215e1021a16fd3e1
Manipulating numbers in JavaScript. · GitHub
April 20, 2020 - Manipulating numbers in JavaScript. Raw · numbers.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters · Show hidden characters · Copy link · Wrong logic in Math.ceil - Will not act like is should for integer values: console.log(Math.ceil(1) == ~~1 + 1) // 1 == 2 ·
🌐
Codecademy
codecademy.com › forum_questions › 4f35e646fe0083000301a5e5
1.2: Why not use Math.ceil? | Codecademy
console.log(Math.floor(52.59)); console.log(Math.ceil(52.59)); Refer to the Mozilla docs for more info: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/ceil https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/floor
Find elsewhere
Top answer
1 of 1
2

The construct:

Math.ceil(averageCost / 10) * 10;

Does a form of rounding. It has the net effect of rounding up to the nearest whole number multiple of 10. So:

11 => 20
20 => 20
21 => 30
11.99 => 20

Math.ceil(averageCost / 10) divides by 10 and rounds up to the nearest whole number (removing all decimal portions and all ones) and then the * 10 brings it back to the same numeric range it was originally in, but without the parts removed by the rounding.

Here's an example showing a number of results:

const nums = [10,11,15,18,19,20,21,10.1,11.99,20.19];

for (let num of nums) {
     let result = Math.ceil(num/10) * 10;
     console.log("Input: ", num, ", Output: ", result);
}


Why wouldn't we just use Math.ceil? Doesn't it effectively do the same thing as the above? Is there a condition where Math.ceil doesn't work?

This combination rounds up to the nearest whole number multiple of 10 whereas Math.ceil() only rounds up to the nearest whole number. So, the two cases you ask about have different uses. Use the one that accomplishes what you want to accomplish. For a number where the integer portion is already a power of ten such as 10.3, the two would have the same output, but for any other number such as 11.3, the two would not have the same output.

Math.ceil(11.3) === 11
(Math.ceil(11.3 / 10) * 10) === 20

Is there a condition where the Math.ceil() function in Javascript doesn't remove decimals from the output?

No. There is not. It's whole function is to round up to the nearest whole number (thus removing any decimal fraction from the number).

So I'm at a loss for why I'd see a division by 10 with a subsequent multiplication of 10.

To round up to the nearest whole number multiple of 10.

🌐
Educative
educative.io › answers › mathceil-mathfloor-and-mathround-in-javascript
Math.ceil, Math.floor, and Math.round in JavaScript
The Math.ceil function in JavaScript is used to round up a number that is passed into it to its nearest integer. What do I mean by rounding up? I mean towards the greater value. Math.ceil() only takes one parameter, the value to be rounded.
🌐
Hugo
gohugo.io › functions › math › ceil
math.Ceil
March 5, 2025 - GitHub 86668 stars Mastodon · Hugo Documentation · Returns the least integer value greater than or equal to the given number. Syntax · math.Ceil VALUE · Returns · float64 · {{ math.Ceil 2.1 }} → 3 · Last updated: March 5, 2025 : content: ...
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › ceilfloortrunc-examples.html
Math.ceil, floor, and trunc Examples — Introduction to Professional Web Development in JavaScript documentation
At first glance, Math.floor and Math.trunc appear to do exactly the same thing. However, a closer look shows that the two methods treat negative numbers differently. ... When combined with the map array method, ceil, floor, and trunc will operate on each entry in an array.
🌐
TutorialsPoint
tutorialspoint.com › javascript › math_ceil.htm
JavaScript Math.ceil() Method
The JavaScript Math.ceil() method accepts a numeric value as a parameter and rounds it UP to the smallest integer greater than or equal to that number. For instance, if we pass a numeric value "7.20" to this method, it rounds it to "8" because it is
🌐
LinkedIn
linkedin.com › pulse › math-ceilin-javascript-luc-constantin
Math ceil()in Javascript
April 9, 2023 - In the example above, I have invoked the ceil() function using the Math class writing the output of the ceil() function to the web browser console so that it would be tested out. Perhaps this might not be the greatest function ever in Javascript, but it did the trick and helped me understand another fundamental core of Javascript.
🌐
Reintech
reintech.io › blog › implementing-math-ceil-method-javascript
Implementing the Math.ceil() Method | Reintech media
January 1, 2026 - In this tutorial, we will learn how to implement the Math.ceil() method in JavaScript. We will look at its syntax, example usage, and use cases for it.
🌐
Accolades Dev
blog.accolades.dev › home › web-development and seo › math.ceil()in javascript
Math.ceil()in Javascript - Accolades Dev
April 14, 2023 - In the example above, I have invoked the ceil() function using the Math class writing the output of the ceil() function to the web browser console so that it would be tested out. Perhaps this might not be the greatest function ever in Javascript, but it did the trick and helped me understand another fundamental core of Javascript.
🌐
Scaler
scaler.com › home › topics › math ceil() javascript
Math ceil() JavaScript- Scaler Topics
June 22, 2022 - The ceil() is a JavaScript function that returns the lowest integer value that is greater than or equal to a given number. In other words, the ceil() method produces an integer value after rounding up a number.