C# Math Abs(Single)

Description

Math Abs(Single) returns the absolute value of a single-precision floating-point number.

Syntax

Math.Abs(Single) has the following syntax.


public static float Abs(
  float value
)

Parameters

Math.Abs(Single) has the following parameters.

  • value - A number that is greater than or equal to Single.MinValue, but less than or equal to Single.MaxValue.

Returns

Math.Abs(Single) method returns A single-precision floating-point number, x, such that 0 d x d Single.MaxValue.

Example

The following example uses the Abs(Single) method to get the absolute value of a number of Single values.


/*  ww w  .j  av a  2 s  .  c  o  m*/
using System;

public class Example
{
   public static void Main()
   {
      float[] values= { Single.MaxValue, 16.354e-12F, 15.123453F, 0F, 
                        -19.123456F, -15.123e17F, Single.MinValue };
      foreach (float value in values)
         Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version