

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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
- Related Questions & Answers
- Java signum() method with Examples
- Java lang.Long.toBinaryString() method with Examples
- Java cbrt() method with Examples
- Java ceil() method with Examples
- Java sqrt() method with Examples
- Java floor() method with Examples
- Java toDegrees() method with Examples
- C# Stack.TrimExcess() Method with Examples
- C# Object.GetHashCode() Method with Examples
- C# Object.GetType() Method with Examples
- C# Queue.TrimExcess() Method with Examples
- jQuery not() method with Examples
- JavaScript removeEventListener() method with examples
- MathF.Tan() Method in C# with Examples
- MathF.Tanh() Method in C# with Examples
- MathF.Truncate() Method in C# with Examples
Advertisements