Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math Ceiling() method is used to return the next highest integer value by rounding up the specified number, if necessary. In other words, it rounds the fraction UP of the given number. The method can be overloaded and it can take decimal and double arguments. In special cases it returns the following:

  • If the argument value is already an integer, the method returns the same as the argument.
  • If the argument is NaN or PositiveInfinity or NegativeInfinity, the method returns the same as the argument.

Syntax

public static decimal Ceiling (decimal arg);
public static double Ceiling (double arg); 

Parameters

arg Specify a number.

Return Value

Returns the next highest integer value by rounding UP the specified number, if necessary.

Example:

In the below example, Ceiling() method is used to round the fraction UP of the specified number.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine(Math.Ceiling(10.5)); 
    Console.WriteLine(Math.Ceiling(-10.5));
    Console.WriteLine(Math.Ceiling(0.5)); 
    Console.WriteLine(Math.Ceiling(-0.5)); 
  }
}

The output of the above code will be:

11
-10
1
-0

❮ C# Math Methods