.Ceiling()

cslylla's avatar
Published Feb 26, 2023Updated Mar 31, 2023
Contribute to Docs

Math.Ceiling() is a class method that always rounds up to the next full integer. It is used to return the smallest integer greater than or equal to the specified number.

Syntax

Math.Ceiling(val);
  • The method takes only one parameter, val, the number to be rounded (as a decimal or double type).

Example

The following example uses Math.Ceiling() to return the next full integer.

// Include the System namespace
using System;
public class Demo {
public static void Main(){
decimal val1 = 6.64M;
decimal val2 = -9.02M;
Console.WriteLine("Solution = " + Math.Ceiling(val1));
Console.WriteLine("Solution = " + Math.Ceiling(val2));
}
}

The example will result in the following output:

Solution = 7
Solution = -9

Codebyte Example

The following example is runnable and uses the Math.Ceiling() method to return the smallest whole number that is greater than or equal to the given double type number:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy