C#中的Decimal.Floor()方法将指定的Decimal数字四舍五入为最接近负负无穷的整数。
以下是语法-
public static decimal Floor (decimal val);
上面的Val是要舍入的值。
现在让我们看一个实现Decimal.Floor()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = 25.25m; Decimal val2 = 11.85m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Floor (val1) = "+Decimal.Floor(val1)); Console.WriteLine("Floor (val2) = "+Decimal.Floor(val2)); } }
输出结果
这将产生以下输出-
Decimal 1 = 25.25 Decimal 2 = 11.85 Floor (val1) = 25 Floor (val2) = 11
现在让我们来看另一个实现Decimal.Floor()方法的示例-
using System; public class Demo { public static void Main(){ Decimal val1 = -25.25m; Decimal val2 = -11.85m; Console.WriteLine("Decimal 1 = "+val1); Console.WriteLine("Decimal 2 = "+val2); Console.WriteLine("Floor (val1) = "+Decimal.Floor(val1)); Console.WriteLine("Floor (val2) = "+Decimal.Floor(val2)); } }
输出结果
这将产生以下输出-
Decimal 1 = -25.25 Decimal 2 = -11.85 Floor (val1) = -26 Floor (val2) = -12