Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c#

What is Math.Ceiling() in C#?

Arslan Bajwa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

C# has a built-in Math class that provides useful mathematical functions and operations. The class has the Ceiling() function, which is used to compute the smallest integral value greater than or equal to a specified number.

Decimal variant

Syntax

public static decimal Ceiling (decimal value);

Parameters

  • value: value is of the Decimal type and represents the input value, which is determined by finding Ceiling(). Its range is all decimal numbers.

Return value

  • Decimal: Ceiling() returns the smallest Decimal number greater than or equal to value.

Double variant

Syntax

public static double Ceiling (double value);

Parameters

  • value: value is of the Double type and represents the input value for which we have to find Ceiling(). Its range is all double numbers.

Return value

  • Double: Ceiling() returns the smallest Double number greater than or equal to value.
  • If value is NaN, infinity, or negative infinity, that value is returned.

Example

using System;
class Educative
{
static void Main()
{
decimal input = 22.32m;
decimal result = Math.Ceiling(input);
System.Console.WriteLine("Ceiling Decimal (22.32) = "+ result);
decimal input1 = 22.0m;
decimal result1 = Math.Ceiling(input1);
System.Console.WriteLine("Ceiling Decimal (22.0) = "+ result1);
double input2 = 22.32;
double result2 = Math.Ceiling(input2);
System.Console.WriteLine("Ceiling Double (22.32) = "+ result2);
double input3 = 22.00;
double result3 = Math.Ceiling(input3);
System.Console.WriteLine("Ceiling Double (22.00) = "+ result3);
}
}

RELATED TAGS

c#

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring