.Ceiling()
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 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
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
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours