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


C# MathF.Ceiling()用法及代碼示例


在C#中,MathF.Ceiling(Single)是MathF類方法。此方法用於查找最小整數,該整數大於或等於參數列表中指定的單值或浮點值。

用法: public static float Ceiling (float x);
Here, x is the float(Single) value whose ceiling value has to be calculated.

返回類型:此方法返回最小的整數值,該值將大於或等於x。


例:

// C# program to illustrate the 
// MathF.Ceiling(Single) Method 
using System; 
  
class GFG { 
  
    // Main method 
    static void Main() 
    { 
  
        // taking float values 
        float x1 = 33.00f; 
        float x2 = 99.99f; 
  
        // Calculate Ceiling values by 
        // Using MathF.Ceiling() method 
        float r1 = MathF.Ceiling(x1); 
        float r2 = MathF.Ceiling(x2); 
  
        // Print the original values 
        // and Ceiling values 
        Console.WriteLine("Input Value  = " + x1); 
        Console.WriteLine("Ceiling value = " + r1); 
  
        // Print the original values 
        // and Ceiling values 
        Console.WriteLine("Input Value  = " + x2); 
        Console.WriteLine("Ceiling value = " + r2); 
    } 
}
輸出:
Input Value  = 33
Ceiling value = 33
Input Value  = 99.99
Ceiling value = 100


相關用法


注:本文由純淨天空篩選整理自Kirti_Mangal大神的英文原創作品 MathF.Ceiling() Method in C# with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。