當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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#。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。