In This Article

DoubleExtensions Class

Provides extension methods for the double type.

public static class DoubleExtensions
Inheritance:
object object

Methods

ClampToNonnegative(double)

Clamps a value to nonnegative number between 0.0..MaxValue.

public static double ClampToNonnegative(this double value)
Parameter Type Description
value double

The value to examine.

Returns

double:

The clamped value.

ClampToPercentage(double)

Clamps a value to a percentage between 0.0..1.0.

public static double ClampToPercentage(this double value)
Parameter Type Description
value double

The value to examine.

Returns

double:

The clamped value.

ClampToRange(double, double, double)

Clamps a value between the specified minimum and maximum.

public static double ClampToRange(this double value, double minimum, double maximum)
Parameter Type Description
value double

The value to examine.

minimum double

The minimum value.

maximum double

The maximum value.

Returns

double:

The clamped value.

IsBetween(double, double, double, bool)

Returns whether a value is between the specified minimum and maximum.

public static bool IsBetween(this double value, double minimum, double maximum, bool isInclusive = true)
Parameter Type Description
value double

The value to examine.

minimum double

The number that the value must be greater than, or equal to if inclusive.

maximum double

The number that the value must be less than, or equal to if inclusive.

isInclusive bool

Whether the check considers minimum and maximum as being inclusive. The default value is true.

Returns

bool:

true if the value is between the specified minimum and maximum; otherwise, false.

IsNonnegative(double)

Returns whether a value is inclusively between 0.0..MaxValue.

public static bool IsNonnegative(this double value)
Parameter Type Description
value double

The value to examine.

Returns

bool:

true if the value is inclusively between 0.0..MaxValue; otherwise, false.

IsPercentage(double)

Returns whether a value is a percentage inclusively between 0.0..1.0.

public static bool IsPercentage(this double value)
Parameter Type Description
value double

The value to examine.

Returns

bool:

true if the value is a percentage inclusively between 0.0..1.0; otherwise, false.

NormalizeDegreeAngle(double)

Normalizes a degree angle to a value between 0.0..360.0.

public static double NormalizeDegreeAngle(this double degreeAngle)
Parameter Type Description
degreeAngle double

The value to normalize.

Returns

double:

The normalized value.

Remarks

Values higher than 360.0 will wrap back to zero (e.g. 540.0 becomes 180.0). A negative degree angle will be translated to its positive equivalent (e.g. -90.0 becomes 270.0).

Round(double, RoundMode)

Returns a number rounded to zero digits using the specified RoundMode.

public static double Round(this double value, RoundMode mode = RoundMode.Nearest)
Parameter Type Description
value double

The value to round.

mode RoundMode

(Optional) The RoundMode to use, whose default is Nearest.

Returns

double:

A rounded number using the specified RoundMode.

Round(double, int, RoundMode)

Returns a number rounded to the specified number of digits using the specified RoundMode.

public static double Round(this double value, int digits, RoundMode mode = RoundMode.Nearest)
Parameter Type Description
value double

The value to round.

digits int

The number of digits in the result.

mode RoundMode

(Optional) The RoundMode to use, whose default is Nearest.

Returns

double:

A rounded number using the specified RoundMode.

RoundToMultiple(double, double)

Returns a number rounded to the nearest multiple of another number.

public static double RoundToMultiple(this double value, double multipleOf)
Parameter Type Description
value double

The value to round.

multipleOf double

The number that defines the multiple.

Returns

double:

A number rounded to the nearest multiple of another number.

Inherited Members