Muokkaa

Jaa


MathF.Round Method

Definition

Overloads

Round(Single, Int32, MidpointRounding)

Rounds a single-precision floating-point value to a specified number of fractional digits using the specified rounding convention.

Round(Single, MidpointRounding)

Rounds a single-precision floating-point value to an integer using the specified rounding convention.

Round(Single)

Rounds a single-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number.

Round(Single, Int32)

Rounds a single-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.

Round(Single, Int32, MidpointRounding)

Source:
MathF.cs
Source:
MathF.cs
Source:
MathF.cs

Rounds a single-precision floating-point value to a specified number of fractional digits using the specified rounding convention.

public:
 static float Round(float x, int digits, MidpointRounding mode);
public static float Round (float x, int digits, MidpointRounding mode);
static member Round : single * int * MidpointRounding -> single
Public Shared Function Round (x As Single, digits As Integer, mode As MidpointRounding) As Single

Parameters

x
Single

The number to round.

digits
Int32

How many fractional digits to keep.

mode
MidpointRounding

The rounding convention to use.

Returns

The rounded representation of x with digits fractional digits using mode rounding convention

Exceptions

digits is less than 0 or greater than 6.

mode is not a valid value of MidpointRounding.

Remarks

The value of the digits argument can range from 0 to 6. The maximum number of integral and fractional digits supported by the Single type is 6.

Important

When rounding midpoint values, the rounding algorithm performs an equality test. Because of problems of binary representation and precision in the floating-point format, the value returned by the method can be unexpected. For more information, see Rounding and precision.

If the value of the x argument is Single.NaN, the method returns Single.NaN. If x is Single.PositiveInfinity or Single.NegativeInfinity, the method returns Single.PositiveInfinity or Single.NegativeInfinity, respectively.

See also

Applies to

Round(Single, MidpointRounding)

Source:
MathF.cs
Source:
MathF.cs
Source:
MathF.cs

Rounds a single-precision floating-point value to an integer using the specified rounding convention.

public:
 static float Round(float x, MidpointRounding mode);
public static float Round (float x, MidpointRounding mode);
static member Round : single * MidpointRounding -> single
Public Shared Function Round (x As Single, mode As MidpointRounding) As Single

Parameters

x
Single

The number to round.

mode
MidpointRounding

The rounding convention to use.

Returns

The rounded representation of x using mode rounding convention

Exceptions

mode is not a valid value of MidpointRounding.

Remarks

Important

When rounding midpoint values, the rounding algorithm performs an equality test. Because of problems of binary representation and precision in the floating-point format, the value returned by the method can be unexpected. For more information, see Rounding and precision.

If the value of the x argument is Single.NaN, the method returns Single.NaN. If x is Single.PositiveInfinity or Single.NegativeInfinity, the method returns Single.PositiveInfinity or Single.NegativeInfinity, respectively.

See also

Applies to

Round(Single)

Source:
MathF.cs
Source:
MathF.cs
Source:
MathF.cs

Rounds a single-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number.

public:
 static float Round(float x);
public static float Round (float x);
static member Round : single -> single
Public Shared Function Round (x As Single) As Single

Parameters

x
Single

The number to round.

Returns

The rounded representation of x

Remarks

This method uses the default rounding convention of MidpointRounding.ToEven.

Important

When rounding midpoint values, the rounding algorithm performs an equality test. Because of problems of binary representation and precision in the floating-point format, the value returned by the method can be unexpected. For more information, see Rounding and precision.

If the value of the x argument is Single.NaN, the method returns Single.NaN. If x is Single.PositiveInfinity or Single.NegativeInfinity, the method returns Single.PositiveInfinity or Single.NegativeInfinity, respectively.

Notes to Callers

Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the Round(Single) method may not appear to round midpoint values to the nearest even integer.

See also

Applies to

Round(Single, Int32)

Source:
MathF.cs
Source:
MathF.cs
Source:
MathF.cs

Rounds a single-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.

public:
 static float Round(float x, int digits);
public static float Round (float x, int digits);
static member Round : single * int -> single
Public Shared Function Round (x As Single, digits As Integer) As Single

Parameters

x
Single

The number to round.

digits
Int32

How many fractional digits to keep.

Returns

The rounded representation of x with digits fractional digits

Exceptions

digits is less than 0 or greater than 6.

Remarks

The value of the digits argument can range from 0 to 6. Note that 6 is the maximum number of integral and fractional digits supported by the Single type.

This method uses the default rounding convention of MidpointRounding.ToEven.

Important

When rounding midpoint values, the rounding algorithm performs an equality test. Because of problems of binary representation and precision in the floating-point format, the value returned by the method can be unexpected. For more information, see Rounding and precision.

If the value of the x argument is Single.NaN, the method returns Single.NaN. If x is Single.PositiveInfinity or Single.NegativeInfinity, the method returns Single.PositiveInfinity or Single.NegativeInfinity, respectively.

See also

Applies to