Math.ceil() returns the ceiled value. It can't change the value of the variable it takes as argument, because Java passes arguments by value. So you need to do

hours = Math.ceil(hours);
Answer from JB Nizet on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › ceil
Math.ceil() - JavaScript | MDN - Mozilla
Because ceil() is a static method of Math, you always use it as Math.ceil(), rather than as a method of a Math object you created (Math is not a constructor).
🌐
Reddit
reddit.com › r/c_programming › ceil() function is not working
r/C_Programming on Reddit: ceil() function is not working
January 6, 2022 -

I have included the math.h header file but ceil() and floor() functions are not working. But pow() function works. I have given the error below.

/usr/bin/ld: /tmp/ccnYHlT4.o: in function `main':

stuff.c:(.text+0x1f): undefined reference to `floor'

collect2: error: ld returned 1 exit status

How to fix this?

Discussions

problem with the ceil function in javascript - Stack Overflow
I keep getting this error when ... says ceil is not a function. ... I also tried to debug it but I don't see any error! As you can see the cal has a value of 2.8 which should be rounded to 3 so what's the problem here? ... You should post your actual code instead screenshots of the code. Otherwise its just guessing. ... Check, what Math.ceil is at ... More on stackoverflow.com
🌐 stackoverflow.com
Math Function "CEILING (number, significance)" does not work properly?
Math Function “CEILING (number, significance)” does not work properly? Example 1: CELING (-1.24) value is changed to “2” (and should be “-1”) Example 2: CELING (-1.24, .1) the value changes to “-1.3” (and should be “-1.2”) in my opinion for example, the function “FLOOR ... More on forums.sketchup.com
🌐 forums.sketchup.com
0
0
January 25, 2015
Uncaught ReferenceError: ceil is not defined
Hiya I have found that a manual calculation of ceil(%field_1%/%field_2%) Does not work, with error Uncaught ReferenceError: ceil is not defined at do_calc_fld_3399490_1 (?page_id=1572&preview=1&cf_... More on github.com
🌐 github.com
5
May 25, 2018
java - Why is Math.ceil not rounding upwards? - Stack Overflow
What's the best explanation that E# is not the same as F? A Holiday to Remember... #04: C-lebrity Squares ... Short story (1970s): Telepathic planetarian thinks a person's thoughts are delusional, kills him, recognizes his error when the spaceship is visible · Axial and equatorial hydrogen atoms in cyclohexane · Some books recommendation by which I can know about what's happening in current mathematics ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Codecademy
codecademy.com › forum_questions › 4f35e646fe0083000301a5e5
1.2: Why not use Math.ceil? | Codecademy
Whereas floor returns the largest integer LESS THAN or equal to a number. Just test it yourself in the Scratchpad with something like this: console.log(Math.floor(52.59)); console.log(Math.ceil(52.59));
🌐
SketchUp Community
forums.sketchup.com › dynamic components
Math Function "CEILING (number, significance)" does not work properly? - Dynamic Components - SketchUp Community
January 25, 2015 - Math Function “CEILING (number, significance)” does not work properly? Example 1: CELING (-1.24) value is changed to “2” (and should be “-1”) Example 2: CELING (-1.24, .1) the value changes to “-1.3” (and should be “-1.2”) in my opinion for example, the function “FLOOR (number, significance)” - is working properly.
🌐
GitHub
github.com › CalderaWP › Caldera-Forms › issues › 2555
Uncaught ReferenceError: ceil is not defined · Issue #2555 · CalderaWP/Caldera-Forms
May 25, 2018 - Calculation using ceil (Math.ceil) doesn't appear to work like other Math functions ·
Published   May 25, 2018
Author   SilvorMike
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_ceil.asp
JavaScript Math ceil() Method
Math.ceil() is an ECMAScript1 (JavaScript 1997) feature.
Top answer
1 of 3
28

This is probably because when you divide an Integer by an Integer you get an Integer back which has the same value as Decimal.round(RoundingMode.DOWN).

system.assertEquals(1, 8/5);
system.assertEquals(8/5, (8.0/5).round(RoundingMode.DOWN);

system.assertEquals(-1, -8/5);
system.assertEquals(-8/5, (-8.0/5).round(RoundingMode.DOWN);

system.assertEquals(2, 7/3);
system.assertEquals(7/3, (7.0/3).round(RoundingMode.DOWN);

If you know you have Integers and you want to get their ceiling, you could do something like:

public static Integer ceiling(Integer x, Integer y)
{
    return Math.ceil(Decimal.valueOf(x).divide(y, /*digits*/ 1));
}
2 of 3
17

Integer Division

In Apex Code, similar to Java, when there are two like numeric data types (e.g. both Integers), then they are calculated in a way that returns the same data type. Integers cannot store fractions, so when you do something like 7/3, the fraction is silently discarded. As far as I know, integer division works in the same for every programming language in the world where the result of integer arithmetic is an integer.In many languages where the result of two integers being divided together results in an integer, the fraction is often dropped entirely, although exceptions do exist (some perform rounding, instead).

Parameter Promotion

You'll notice that there's no function Math.ceil that accepts an Integer. This means if you give it an integer, it will implicitly be cast to a floating point value before being processed by Math.ceil.

Arithmetic Promotion

When two numbers are operated on using the standard operators (+, -, /, *), if one of those parameters are a floating point value, the other one will also automatically become a floating point value. Similarly, if a integer and a long were involved in an operation, both numbers become long, and the return type becomes long. So, the goal is to create a situation where a floating point is returned. For example, this results in the correct result:

Integer x = Math.ceil(7.0/3).intValue();

Here, the 7.0 indicates a floating point operation. You'd also get the same effect if you did this:

Decimal x = 7;
Integer y = 3;
Integer z = Math.ceil(x/y).intValue();

This behavior is well-defined, and mimics the behavior in Java. You can read more about automatic widening conversion in the Java documentation, as well as rules about integer division. You'll find that, while not explicitly mentioned in the Apex Code Developer's Guide (as far as I can tell), it obeys the same rules.

🌐
Sololearn
sololearn.com › en › Discuss › 2411707 › why-is-mathceil-function-malfunctioning-in-code-coach-section
Why is Math.ceil function malfunctioning in code coach section... | Sololearn: Learn to code for FREE!
Thanks Jayakrishna🇮🇳 ... Math.ceil requires double parameters ... Aaron 5/2 result 2 because both integers. If you want to get decimal point value, you need to have atleast one float or double value.. as 5.0/2 or 5/2.0 then you get 2.5 ...
🌐
Wikipedia
en.wikipedia.org › wiki › Floor_and_ceiling_functions
Floor and ceiling functions - Wikipedia
February 5, 2026 - In most programming languages, the simplest method to convert a floating point number to an integer does not do floor or ceiling, but truncation. The reason for this is historical, as the first machines used ones' complement and truncation was ...
🌐
Cppreference
en.cppreference.com › w › cpp › numeric › math › ceil.html
std::ceil, std::ceilf, std::ceill - cppreference.com
The library provides overloads of std::ceil for all cv-unqualified floating-point types as the type of the parameter.(since C++23) If no errors occur, the smallest integer value not less than num, that is ⌈num⌉, is returned. ... Errors are reported as specified in math_errhandling.
🌐
Codecademy
codecademy.com › forum_questions › 4f977513839b6d0003005464
2.1 Is there some reason no one uses Math.ceil? | Codecademy
Math.random() returns a random float between 0 and 1, *10 makes it between 0 and 10(not inclusive!), add 1 to make it between 1 and 11, which is floor()ed to an integer between 1 and 10(inclusive) ... The reason is that Math.random() returns a number that is greater than or equal to 0 but strictly less than 1. So your example of Math.ceil(Math.random() * 10) would actually return a number between 0 and 10, not what we want.
🌐
Codecademy
codecademy.com › forum_questions › 4f2326510884e8000100e919
Is there a reason Math.ceil was not used instead of Math.floor? | Codecademy
If you really want to use Math.ceil you need to avoid the zero case from the random number generator. This is possible by first subtracting the random value from 1 and multiplying by 6. ... Note that this will not produce the same sequence as ...
🌐
O'Reilly
oreilly.com › library › view › javascript-the-definitive › 0596101996 › re106.html
Math.ceil( ): round a number up — ECMAScript v1 - JavaScript: The Definitive Guide, 5th Edition [Book]
August 17, 2006 - Math.ceil( ) computes the ceiling function—i.e., it returns the closest integer value that is greater than or equal to the function argument. Math.ceil( ) differs from Math.round( ) in that it always rounds up, rather than rounding up or down ...
Author   David Flanagan
Published   2006
Pages   1018
🌐
Tutorialspoint
tutorialspoint.com › python › number_ceil.htm
Python math.ceil() Method
The Python math.ceil() method is used to find the nearest greater integer of a numeric value. For example, the ceil value of the floating-point number 3.6 is 4. The process involved is almost similar to the estimation or rounding off technique.