指定された精度の、指定値に最も近い数値を返します。
Overloads Public Shared Function Round( _
ByVal d As Decimal, _ ByVal decimals As Integer _) As Decimal
[C#]
public static decimal Round(decimald,intdecimals);
[C++]
public: static Decimal Round(Decimald,intdecimals);
[JScript]
public static function Round(
d : Decimal,decimals : int) : Decimal;
パラメータ
- d
丸め対象の Decimal 数。 - decimals
戻り値の小数点以下の有効桁数 (精度)。
戻り値
decimals に等しい精度の、最も d に近い数値。 d が 2 つの整数 (一方の整数が偶数でもう一方が奇数) の中間にある場合は偶数が返されます。 d の精度が decimals 未満の場合は、 d は変更されずに返されます。
解説
decimals パラメータでは 0 ~ 28 までの戻り値の有効小数桁数が指定されます。 decimals が 0 の場合は整数が返されます。
このメソッドの動作は、IEEE 規格 754、セクション 4 に従います。このような丸めは、近似値への丸めまたは銀行の丸めと呼ばれることがあります。 decimals を 0 にする場合、この丸めは 0 への丸めと呼ばれることがあります。
使用例
近似値に丸められるコード例を次に示します。
Math.Round(3.44, 1) 'Returns 3.4.
Math.Round(3.45, 1) 'Returns 3.4.
Math.Round(3.46, 1) 'Returns 3.5.
[C#]
Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.
[C++]
Math::Round(3.44, 1); //Returns 3.4.
Math::Round(3.45, 1); //Returns 3.4.
Math::Round(3.46, 1); //Returns 3.5.
[JScript]
System.Math.Round(3.44, 1) //Returns 3.4.
System.Math.Round(3.45, 1) //Returns 3.4.
System.Math.Round(3.46, 1) //Returns 3.5.
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
Math クラス | Math メンバ | System 名前空間 | Math.Round オーバーロードの一覧 | Ceiling | Floor