.Ceiling()

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

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C# on Codecademy