.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 adecimal
ordouble
type).
Example
The following example uses Math.Ceiling()
to return the next full integer.
// Include the System namespaceusing 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 = 7Solution = -9