MathF.Sign() Method in C# with Examples
Last Updated :
04 Apr, 2019
In C#, MathF.Sign(Single) is a MathF class method which returns an integer that specify the sign of the number.
Syntax: public static int Sign (float x);
Here, x is the required single precision floating-point number whose sign has to be calculated.
Return Type: This method returns the value of type System.Int32 as per following mentioned conditions:
Return Value |
Condition: |
0 |
If value is equal to zero |
1 |
If value is greater than zero |
-1 |
If value is lesser than zero |
Example:
using System;
class GFG {
static void Main( string [] args)
{
float f1 = 746.89f;
float f2 = -782.1247f;
Console.WriteLine(check(MathF.Sign(f1)));
Console.WriteLine(check(MathF.Sign(f2)));
}
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" ;
}
}
|
Output:
Greater than zero
Less than zero
Share your thoughts in the comments
Please Login to comment...