📜  C#中的Decimal.Ceiling()方法

📅  最后修改于: 2021-05-29 15:36:39             🧑  作者: Mango

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

下面的程序说明了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