Thursday, August 12, 2010

C#: How to round up a floating-point number

If you need to round up a floating-point number to the closest integer, then you can use the System.Math.Ceiling method:

System.Math.Ceiling(3.0)  // Returns 3
System.Math.Ceiling(3.4)  // Returns 4
System.Math.Ceiling(3.8)  // Returns 4