- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MathF.Sign() Method in C# with Examples
The MathF.Sign() method in C# returns an integer specifying the sign of the number.
Syntax
Following is the syntax −
public static int Sign (float val);
Above, Val is the floating-point number whose sign is to be calculated.
The return value is 0 if Val is zero. It’s -1 if the value is less than zero and 1 if the value is greater than zero.
Example
Let us now see an example to implement the MathF.Sign() method −
using System; public class Demo { public static void Main(){ float val1 = 10.23898f; float val2 = -20.878788f; Console.WriteLine("MathF.Sign(val1) = "+MathF.Sign(val1)); Console.WriteLine("MathF.Sign(val2) = "+MathF.Sign(val2)); } }
Output
This will produce the following output −
MathF.Sign(val1) = 1 MathF.Sign(val2) = -1
Example
Let us now see another example to implement the MathF.Sign() method −
using System; public class Demo { public static void Main(){ float val1 = 0.00f; float val2 = -10.6735f; Console.WriteLine("MathF.Sign(val1) = "+MathF.Sign(val1)); Console.WriteLine("MathF.Sign(val2) = "+MathF.Sign(val2)); } }
Output
This will produce the following output −
MathF.Sign(val1) = 0 MathF.Sign(val2) = -1
Advertisements