Table of Contents

Struct float

Namespace
System
Assembly
mscorlib.dll

Represents a single-precision floating-point number.

public float
Inherited Members

Fields

Epsilon

Represents the smallest positive Single value that is greater than zero. This field is constant.

public const float Epsilon = 1E-45

Field Value

float

MaxValue

Represents the largest possible value of Single. This field is constant.

public const float MaxValue = 3.4028235E+38

Field Value

float

Remarks

The value of this constant is positive 3.40282347E+38.

MinValue

Represents the smallest possible value of Single. This field is constant.

public const float MinValue = -3.4028235E+38

Field Value

float

Remarks

The value of this constant is negative 3.402823e38.

NaN

Represents a value that is not a number (NaN). This field is constant.

public const float NaN = NaN

Field Value

float

NegativeInfinity

Represents negative infinity. This field is constant.

public const float NegativeInfinity = -Infinity

Field Value

float

PositiveInfinity

Represents positive infinity. This field is constant.

public const float PositiveInfinity = Infinity

Field Value

float

Methods

CompareTo(float)

Compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number.

public int CompareTo(float value)

Parameters

value float

A single-precision floating-point number to compare.

Returns

int

A signed number indicating the relative values of this instance and value. Less than zero: This instance is less than value. -or- This instance is not a number (NaN) and value is a number. Zero: This instance is equal to value. -or- Both this instance and value are not a number (NaN), PositiveInfinity, or NegativeInfinity. Greater than zero: This instance is greater than value. -or- This instance is a number and value is not a number (NaN).

IsInfinity(float)

Returns a value indicating whether the specified number evaluates to negative or positive infinity.

public static bool IsInfinity(float f)

Parameters

f float

A single-precision floating-point number.

Returns

bool

true if f evaluates to PositiveInfinity or NegativeInfinity; otherwise, false.

IsNaN(float)

Returns a value that indicates whether the specified value is not a number (NaN).

public static bool IsNaN(float f)

Parameters

f float

A single-precision floating-point number.

Returns

bool

true if f evaluates to NaN; otherwise, false.

IsNegativeInfinity(float)

Returns a value indicating whether the specified number evaluates to negative infinity.

public static bool IsNegativeInfinity(float f)

Parameters

f float

A single-precision floating-point number.

Returns

bool

true if f evaluates to NegativeInfinity; otherwise, false.

IsPositiveInfinity(float)

Returns a value indicating whether the specified number evaluates to positive infinity.

public static bool IsPositiveInfinity(float f)

Parameters

f float

A single-precision floating-point number.

Returns

bool

true if d evaluates to PositiveInfinity; otherwise, false.

Parse(string)

Converts the string representation of a number to its single-precision floating-point number equivalent.

public static float Parse(string s)

Parameters

s string

A string that contains a number to convert.

Returns

float

A single-precision floating-point number equivalent to the numeric value or symbol specified in

s
.

Exceptions

ArgumentNullException

s is null.

ToString()

Converts the numeric value of this instance to its equivalent string representation.

public override string ToString()

Returns

string

The string representation of the value of this instance.

ToString(string)

Converts the numeric value of this instance to its equivalent string representation, using the specified format.

public string ToString(string format)

Parameters

format string

A numeric format string.

Returns

string

The string representation of the value of this instance as specified by format.

TryParse(string, out float)

Converts the string representation of a number to its single-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.

public static bool TryParse(string s, out float result)

Parameters

s string

A string containing a number to convert.

result float

When this method returns, contains single-precision floating-point number equivalent to the numeric value or symbol contained in s, if the conversion succeeded, or zero if the conversion failed. The conversion fails if the s parameter is null or Empty, is not a number in a valid format, or represents a number less than MinValue or greater than MaxValue. This parameter is passed uninitialized; any value originally supplied in result will be overwritten.

Returns

bool

true if s was converted successfully; otherwise, false.

Remarks

Values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification.

This overload differs from the Parse(string) method by returning a bool value that indicates whether the parse operation succeeded instead of returning the parsed numeric value. It eliminates the need to use exception handling to test for a FormatException in the event that s is invalid and cannot be successfully parsed.