
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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.Abs() Method in C# with Examples
The MathF.Abs() method in C# is used to return the absolute value of a float number.
Syntax
Following is the syntax −
public static float Abs (float val);
Above, the parameter Val is the specified float number.
Example
Let us now see an example to implement the MathF.Abs() method −
using System; public class Demo { public static void Main(){ float val1 = 20.5f; float val2 = -89.5f; Console.WriteLine("Absolute float value1 = "+(MathF.Abs(val1))); Console.WriteLine("Absolute float value2 = "+(MathF.Abs(val2))); } }
Output
This will produce the following output −
Absolute float value1 = 20.5 Absolute float value2 = 89.5
Example
Let us now see another example to implement the MathF.Abs() method −
using System; public class Demo { public static void Main(){ float val1 = 0.1f; float val2 = 1.0f; Console.WriteLine("Absolute float value1 = "+(MathF.Abs(val1))); Console.WriteLine("Absolute float value2 = "+(MathF.Abs(val2))); } }
Output
This will produce the following output −
Absolute float value1 = 0.1 Absolute float value2 = 1
Advertisements