MathF.Round 方法

定义

重载

名称 说明
Round(Single, Int32, MidpointRounding)

使用指定的舍入约定将单精度浮点值舍入到指定数量的小数位数。

Round(Single, MidpointRounding)

使用指定的舍入约定将单精度浮点值舍入为整数。

Round(Single)

将单精度浮点值舍入到最接近的整数值,并将中点值舍入到最接近的偶数。

Round(Single, Int32)

将单精度浮点值舍入到指定的小数位数,并将中点值舍入到最接近的偶数。

Round(Single, Int32, MidpointRounding)

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

使用指定的舍入约定将单精度浮点值舍入到指定数量的小数位数。

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

参数

x
Single

要舍入的数值。

digits
Int32

要保留的分数位数。

mode
MidpointRounding

要使用的舍入约定。

返回

使用x舍入约定的digits带小数位数的mode舍入表示形式

例外

digits 小于 0 或大于 6。

mode 不是有效值 MidpointRounding

注解

参数的值 digits 可以介于 0 到 6 范围内。 类型支持 Single 的最大整型和小数位数为 6。

Important

舍入中点值时,舍入算法将执行相等性测试。 由于浮点格式的二进制表示形式和精度问题,因此该方法返回的值可能意外。 有关详细信息,请参阅 舍入和精度

如果参数的值为x,则该方法返回 Single.NaNSingle.NaN 如果 xSingle.PositiveInfinitySingle.NegativeInfinity,则该方法分别返回 Single.PositiveInfinitySingle.NegativeInfinity返回。

另请参阅

适用于

Round(Single, MidpointRounding)

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

使用指定的舍入约定将单精度浮点值舍入为整数。

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

参数

x
Single

要舍入的数值。

mode
MidpointRounding

要使用的舍入约定。

返回

使用x舍入约定的mode舍入表示形式

例外

mode 不是有效值 MidpointRounding

注解

Important

舍入中点值时,舍入算法将执行相等性测试。 由于浮点格式的二进制表示形式和精度问题,因此该方法返回的值可能意外。 有关详细信息,请参阅 舍入和精度

如果参数的值为x,则该方法返回 Single.NaNSingle.NaN 如果 xSingle.PositiveInfinitySingle.NegativeInfinity,则该方法分别返回 Single.PositiveInfinitySingle.NegativeInfinity返回。

另请参阅

适用于

Round(Single)

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

将单精度浮点值舍入到最接近的整数值,并将中点值舍入到最接近的偶数。

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

参数

x
Single

要舍入的数值。

返回

舍入表示形式 x

注解

此方法使用默认舍入约定。MidpointRounding.ToEven

Important

舍入中点值时,舍入算法将执行相等性测试。 由于浮点格式的二进制表示形式和精度问题,因此该方法返回的值可能意外。 有关详细信息,请参阅 舍入和精度

如果参数的值为x,则该方法返回 Single.NaNSingle.NaN 如果 xSingle.PositiveInfinitySingle.NegativeInfinity,则该方法分别返回 Single.PositiveInfinitySingle.NegativeInfinity返回。

调用方说明

由于精度丢失,因此,由于将小数值表示为浮点数或对浮点值执行算术运算,在某些情况下 Round(Single) ,该方法可能不会将中点值舍入到最接近的偶数整数。

另请参阅

适用于

Round(Single, Int32)

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

将单精度浮点值舍入到指定的小数位数,并将中点值舍入到最接近的偶数。

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

参数

x
Single

要舍入的数值。

digits
Int32

要保留的分数位数。

返回

x小数位数的digits舍入表示形式

例外

digits 小于 0 或大于 6。

注解

参数的值 digits 可以介于 0 到 6 范围内。 请注意,6 是类型支持 Single 的最大整数和小数位数。

此方法使用默认舍入约定。MidpointRounding.ToEven

Important

舍入中点值时,舍入算法将执行相等性测试。 由于浮点格式的二进制表示形式和精度问题,因此该方法返回的值可能意外。 有关详细信息,请参阅 舍入和精度

如果参数的值为x,则该方法返回 Single.NaNSingle.NaN 如果 xSingle.PositiveInfinitySingle.NegativeInfinity,则该方法分别返回 Single.PositiveInfinitySingle.NegativeInfinity返回。

另请参阅

适用于