C#中的Decimal.Ceiling()方法
C#中的Decimal.Ceiling()方法用于返回大于或等于指定的十进制数字的最小整数值。
语法
以下是语法-
public static decimal Ceiling (decimal val);
上面的Val是十进制数。
示例
现在让我们看一个实现Decimal.Ceiling()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = 12.85m; Decimal val2 = 3.45m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Ceiling (val1) = "+Decimal.Ceiling(val1)); Console.WriteLine("Ceiling (val2) = "+Decimal.Ceiling(val2)); } }
输出结果
这将产生以下输出-
Decimal 1 = 12.85 Decimal 2 = 3.45 Ceiling (val1) = 13 Ceiling (val2) = 4
示例
现在让我们来看另一个实现Decimal.Ceiling()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = -10.85m; Decimal val2 = -33.45m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Ceiling (val1) = "+Decimal.Ceiling(val1)); Console.WriteLine("Ceiling (val2) = "+Decimal.Ceiling(val2)); } }
输出结果
这将产生以下输出-
Decimal 1 = -10.85 Decimal 2 = -33.45 Ceiling (val1) = -10 Ceiling (val2) = -33