📜  C#中的MathF.Sign()方法与示例

📅  最后修改于: 2021-05-29 22:58:25             🧑  作者: Mango

在C#中, MathF.Sign(Single)是MathF类方法,该方法返回一个整数,该整数指定数字的符号。

返回类型:该方法根据以下条件返回System.Int32类型的值:

Return Value Condition:
0 If value is equal to zero
1 If value is greater than zero
-1 If value is lesser than zero

例子:

// C# program to demonstrate the
// MathF.Sign(Single) Method
using System;
  
class GFG {
  
    // Main Method
    static void Main(string[] args)
    {
  
        // float data type
        float f1 = 746.89f;
        float f2 = -782.1247f;
  
        // displaying result
        Console.WriteLine(check(MathF.Sign(f1)));
        Console.WriteLine(check(MathF.Sign(f2)));
    }
  
    // function to check whether the input
    // number is greater than zero or not
    public static String check(int r)
    {
        if (r == 0)
            return "Equal to zero";
  
        else if (r < 0)
            return "Less than zero";
  
        else
            return "Greater than zero";
    }
}
输出:
Greater than zero
Less than zero