当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Decimal.Floor()用法及代码示例


此方法用于将小数点四舍五入为负无穷大的最接近的整数。

用法: public static decimal Floor (decimal d);

参数:
d:此参数指定要四舍五入的小数。


返回值:如果d具有小数部分,则小于d或d的负整数的下一个整数十进制数没有小数部分,则d不变地返回。请注意,该方法返回Decimal类型的整数值。

以下示例程序旨在说明Decimal.Floor(Decimal)方法的用法:

示例1:

// C# program to demonstrate the 
// Decimal.Floor(Decimal) Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring the decimal variable 
        Decimal a = 4.01m; 
  
        // finding the floor of the Decimal value 
        // using floor() method; 
        Decimal value = Decimal.Floor(a); 
  
        // Display the Floor 
        Console.WriteLine("Floor Value is : {0}", 
                                          value); 
    } 
}
输出:
Floor Value is : 4

示例2:

// C# program to demonstrate the 
// Decimal.Floor(Decimal) Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring the decimal variable 
        Decimal a = -5.03m; 
  
        // finding the floor of the Decimal value 
        // using floor() method; 
        Decimal value = Decimal.Floor(a); 
  
        // Display the Floor 
        Console.WriteLine("Floor Value is : {0}", 
                                          value); 
    } 
}
输出:
Floor Value is : -6

示例3:

// C# program to demonstrate the 
// Decimal.Floor(Decimal) Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring the decimal variable 
        Decimal a = 2.00m; 
  
        // finding the floor of  
        // the Decimal value 
        // using floor() method; 
        Decimal value = Decimal.Floor(a); 
  
        // Display the Floor 
        Console.WriteLine("Floor Value is : {0}", 
                                          value); 
    } 
}
输出:
Floor Value is : 2


相关用法


注:本文由纯净天空筛选整理自IshwarGupta大神的英文原创作品 Decimal.Floor() Method in C#。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。