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


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


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

用法:public static decimal Ceiling (decimal d);
Here d is the decimal whose ceiling value is to be calculated.

返回值:它返回大于或等于d参数的最小整数值。请注意,此方法返回的是Decimal而不是整数类型。


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

示例1:

// C# program to demonstrate the 
// Decimal.Ceiling(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 ceiling of  
        // the Decimal value 
        // using ceiling() method; 
        Decimal value = Decimal.Ceiling(a); 
  
        // Display the ceiling 
        Console.WriteLine("Ceiling Value is : {0}", 
                                            value); 
    } 
}
输出:
Ceiling Value is : 5

示例2:

// C# program to demonstrate the 
// Decimal.Ceiling(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 Ceiling of 
        // the Decimal value 
        // using Ceiling() method; 
        Decimal value = Decimal.Ceiling(a); 
  
        // Display the Ceiling 
        Console.WriteLine("Ceiling Value is : {0}", 
                                            value); 
    } 
}
输出:
Ceiling Value is : -5

示例3:

// C# program to demonstrate the 
// Decimal.Ceiling(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 Ceiling of 
        // the Decimal value 
        // using Ceiling() method; 
        Decimal value = Decimal.Ceiling(a); 
  
        // Display the Ceiling 
        Console.WriteLine("Ceiling Value is : {0}", 
                                            value); 
    } 
}
输出:
Ceiling Value is : 2


相关用法


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