# Math.RoundMath.RoundMath.RoundMath.Round Method

## オーバーロード

 Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding) 10 進数の値は指定した小数部の桁数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a decimal value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values. Round(Double, Int32, MidpointRounding) Round(Double, Int32, MidpointRounding) Round(Double, Int32, MidpointRounding) Round(Double, Int32, MidpointRounding) 倍精度浮動小数点の値は指定した小数部の桁数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a double-precision floating-point value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values. Round(Double, MidpointRounding) Round(Double, MidpointRounding) Round(Double, MidpointRounding) Round(Double, MidpointRounding) 倍精度浮動小数点の値は最も近い整数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a double-precision floating-point value to the nearest integer, and uses the specified rounding convention for midpoint values. Round(Double, Int32) Round(Double, Int32) Round(Double, Int32) Round(Double, Int32) 倍精度浮動小数点の値は指定した小数部の桁数に丸められ、中間値は最も近い偶数値に丸められます。Rounds a double-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. Round(Double) Round(Double) Round(Double) Round(Double) 倍精度浮動小数点の値は最も近い整数値に丸められ、中間値は最も近い偶数値に丸められます。Rounds a double-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number. Round(Decimal, Int32) Round(Decimal, Int32) Round(Decimal, Int32) Round(Decimal, Int32) 10 進数の値は指定した小数部の桁数に丸められ、中間値は最も近い偶数値に丸められます。Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. Round(Decimal) Round(Decimal) Round(Decimal) Round(Decimal) 10 進数の値は最も近い整数値に丸められ、中間値は最も近い偶数値に丸められます。Rounds a decimal value to the nearest integral value, and rounds midpoint values to the nearest even number. Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding) 10 進数の値は最も近い整数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a decimal value to the nearest integer, and uses the specified rounding convention for midpoint values.

## 例

この記事の C# 例は、Try.NET インライン コード ランナーとプレイグラウンドで実行されます。The C# examples in this article run in the Try.NET inline code runner and playground. [実行] ボタンを選択すると、対話型ウィンドウで例が実行されます。Select the Run button to run an example in an interactive window. コードを実行したら、コードを変更し、[実行] をもう一度選択して変更後のコードを実行できます。Once you execute the code, you can modify it and run the modified code by selecting Run again. 変更後のコードが対話型ウィンドウで実行されるか、コンパイルできなかった場合、対話型ウィンドウにすべての C# コンパイラ エラー メッセージが表示されます。The modified code either runs in the interactive window or, if compilation fails, the interactive window displays all C# compiler error messages.

## 注釈

このセクションの内容:In this section:

#### どのメソッドが呼び出しですか。Which method do I call?

または-or-

Round(Double)

または-or-

Round(Double, MidpointRounding)

または-or-

Round(Double, Int32)

または-or-

Round(Double, Int32, MidpointRounding)
Round、Singleを指定した指定した丸め規則と有効桁数の損失を最小限に抑えることを使用して桁の小数部の値。Round a Single value to a specified number of fractional digits by using a specified rounding convention and minimizing the loss of precision. 変換、SingleDecimalを呼び出すとRound(Decimal, Int32, MidpointRounding)します。Convert the Single to a Decimal and call Round(Decimal, Int32, MidpointRounding).

#### 中間値と丸め規則Midpoint values and rounding conventions

Roundメソッドは、中間値を処理するための 2 つの丸め規則をサポートしています。The Round method supports two rounding conventions for handling midpoint values:

• ゼロから離れる方向に丸め処理Rounding away from zero

中間値は、次の番号をゼロから離れる方向に丸められます。Midpoint values are rounded to the next number away from zero. 次の例では、3.75 が 3.8 に四捨五入-3.8 に 3.9 に 3.85 ラウンド-3.75 が丸められ、-3.85-3.9 に桁に丸めます。For example, 3.75 rounds to 3.8, 3.85 rounds to 3.9, -3.75 rounds to -3.8, and -3.85 rounds to -3.9. この形式の丸めがによって表される、MidpointRounding.AwayFromZero列挙型のメンバー。This form of rounding is represented by the MidpointRounding.AwayFromZero enumeration member.

ゼロから離れる方向に丸め処理は、丸め処理の最もよく知られた形式です。Rounding away from zero is the most widely known form of rounding.

• 、近似値に丸め処理や銀行型丸めRounding to nearest, or banker's rounding

中間値は、最も近い偶数に丸められます。Midpoint values are rounded to the nearest even number. たとえば、3.75 と 3.85 の両方が 3.8 に丸める、-3.75 と-3.85 の両方が-3.8 に丸めます。For example, both 3.75 and 3.85 round to 3.8, and both -3.75 and -3.85 round to -3.8. この形式の丸めがによって表される、MidpointRounding.ToEven列挙型のメンバー。This form of rounding is represented by the MidpointRounding.ToEven enumeration member.

近似値に丸め処理は、財務や統計操作で使用される丸め処理の標準的な形式です。Rounding to nearest is the standard form of rounding used in financial and statistical operations. IEEE 標準 754、セクション 4 に準拠しています。It conforms to IEEE Standard 754, section 4. 複数の丸め処理で使用する場合、常に中間値を 1 つの方向に丸めるによって引き起こされる丸めエラーが減少します。When used in multiple rounding operations, it reduces the rounding error that is caused by consistently rounding midpoint values in a single direction. 場合によっては、この丸めエラーは大幅にできます。In some cases, this rounding error can be significant.

次の例は、常に中間値を 1 つの方向に丸めることができます、バイアスを示しています。The following example illustrates the bias that can result from consistently rounding midpoint values in a single direction. 配列の真の平均を計算する例では、Decimal値、および 2 つの規則を使用して、配列内の値が丸められたときに、平均を計算します。The example computes the true mean of an array of Decimal values, and then computes the mean when the values in the array are rounded by using the two conventions. この例では、真の平均と、平均の近似値に丸め処理を行うときに、結果は同じです。In this example, the true mean and the mean that results when rounding to nearest are the same. ただし、ゼロから離れる方向に丸め処理と生成される平均異なります.05 (または 3.6%)真の平均です。However, the mean that results when rounding away from zero differs by .05 (or by 3.6%) from the true mean.

``````using System;

public class Example
{
public static void Main()
{
decimal[] values = { 1.15m, 1.25m, 1.35m, 1.45m, 1.55m, 1.65m };
decimal sum = 0;

// Calculate true mean.
foreach (var value in values)
sum += value;

Console.WriteLine("True mean:     {0:N2}", sum/values.Length);

// Calculate mean with rounding away from zero.
sum = 0;
foreach (var value in values)
sum += Math.Round(value, 1, MidpointRounding.AwayFromZero);

Console.WriteLine("AwayFromZero:  {0:N2}", sum/values.Length);

// Calculate mean with rounding to nearest.
sum = 0;
foreach (var value in values)
sum += Math.Round(value, 1, MidpointRounding.ToEven);

Console.WriteLine("ToEven:        {0:N2}", sum/values.Length);
}
}
// The example displays the following output:
//       True mean:     1.40
//       AwayFromZero:  1.45
//       ToEven:        1.40
``````
``````Module Example
Public Sub Main()
Dim values() As Decimal = { 1.15d, 1.25d, 1.35d, 1.45d, 1.55d, 1.65d }
Dim sum As Decimal

' Calculate true mean.
For Each value In values
sum += value
Next
Console.WriteLine("True mean:     {0:N2}", sum/values.Length)

' Calculate mean with rounding away from zero.
sum = 0
For Each value In values
sum += Math.Round(value, 1, MidpointRounding.AwayFromZero)
Next
Console.WriteLine("AwayFromZero:  {0:N2}", sum/values.Length)

' Calculate mean with rounding to nearest.
sum = 0
For Each value In values
sum += Math.Round(value, 1, MidpointRounding.ToEven)
Next
Console.WriteLine("ToEven:        {0:N2}", sum/values.Length)
End Sub
End Module
' The example displays the following output:
'       True mean:     1.40
'       AwayFromZero:  1.45
'       ToEven:        1.40
``````

Round(Decimal) ToEven
Round(Double) ToEven
Round(Decimal, Int32) ToEven
Round(Double, Int32) ToEven
Round(Decimal, MidpointRounding) によって決定`mode`パラメーター。Determined by `mode` parameter.
Round(Double, MidpointRounding) によって決定`mode`パラメーターDetermined by `mode` parameter
Round(Decimal, Int32, MidpointRounding) によって決定`mode`パラメーターDetermined by `mode` parameter
Round(Double, Int32, MidpointRounding) によって決定`mode`パラメーターDetermined by `mode` parameter

### 丸め処理や有効桁数Rounding and precision

この問題を説明する例を次に示します。The following example illustrates the problem. 繰り返し、.1 に 11.0 を追加し、結果を最も近い整数に丸めます。It repeatedly adds .1 to 11.0 and rounds the result to the nearest integer. 丸めの規則に関係なく 11.5 は 12 に丸める必要があります。Regardless of the rounding convention, 11.5 should round to 12. ただし、例の出力として存在しません。However, as the output from the example shows, it does not. 例では、"R"を使用して標準数値書式指定文字列表示には、値の完全な有効桁数、および値は切り捨てられますが、繰り返しの追加中に有効桁数を失ったことを示しています、浮動小数点し、その値が実際には11.499999999999998 します。The example uses the "R" standard numeric format string to display the floating point value's full precision, and shows that the value to be rounded has lost precision during repeated additions, and its value is actually 11.499999999999998. .499999999999998.5 未満であるため、値は [次へ] の最大の整数に丸められません。Because .499999999999998 is less than .5, the value is not rounded to the next highest integer. 定数の値に対して 11.5 に割り当てるだけですがある場合、例に示すことも、この問題は発生しません、Double変数。As the example also shows, this problem does not occur if we simply assign the constant value 11.5 to a Double variable.

``````using System;

public class Example
{
public static void Main()
{
Console.WriteLine("{0,5} {1,20:R}  {2,12} {3,15}\n",
"Value", "Full Precision", "ToEven",
"AwayFromZero");
double value = 11.1;
for (int ctr = 0; ctr <= 5; ctr++)

Console.WriteLine();

value = 11.5;
}

private static double RoundValueAndAdd(double value)
{
Console.WriteLine("{0,5:N1} {0,20:R}  {1,12} {2,15}",
value, Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero));
return value + .1;
}
}
// The example displays the following output:
//       Value       Full Precision        ToEven    AwayFromZero
//
//        11.1                 11.1            11              11
//        11.2                 11.2            11              11
//        11.3   11.299999999999999            11              11
//        11.4   11.399999999999999            11              11
//        11.5   11.499999999999998            11              11
//        11.6   11.599999999999998            12              12
//
//        11.5                 11.5            12              12
``````
``````Module Example
Public Sub Main()
Dim value As Double = 11.1

Console.WriteLine("{0,5} {1,20:R}  {2,12} {3,15}",
"Value", "Full Precision", "ToEven",
"AwayFromZero")
Console.WriteLine()
For ctr As Integer = 0 To 5
Next
Console.WriteLine()

value = 11.5
End Sub

Private Function RoundValueAndAdd(value As Double) As Double
Console.WriteLine("{0,5:N1} {0,20:R}  {1,12} {2,15}",
value, Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero))
Return value + .1
End Function
End Module
' The example displays the following output:
'       Value       Full Precision        ToEven    AwayFromZero
'
'        11.1                 11.1            11              11
'        11.2                 11.2            11              11
'        11.3   11.299999999999999            11              11
'        11.4   11.399999999999999            11              11
'        11.5   11.499999999999998            11              11
'        11.6   11.599999999999998            12              12
'
'        11.5                 11.5            12              12
``````

• ときに小数部の値は、浮動小数点型のバイナリ形式で正確に表現できません。When a fractional value cannot be expressed precisely in the floating-point type's binary format.

• ときに値が切り捨てられますが、1 つまたは複数の浮動小数点演算から計算されます。When the value to be rounded is calculated from one or more floating-point operations.

• 丸め対象の値が、SingleなくDoubleまたはDecimalします。When the value to be rounded is a Single rather than a Double or Decimal. 詳細については、次のセクションを参照してください。丸めと単精度浮動小数点値します。For more information, see the next section, Rounding and single-precision floating-point values.

• 丸め演算が四捨五入するオーバー ロードを呼び出す場合、Double値を変更できます、DoubleDecimal値し、四捨五入するオーバー ロードを呼び出して、Decimal値の代わりにします。If the rounding operation calls an overload that rounds a Double value, you can change the Double to a Decimal value and call an overload that rounds a Decimal value instead. ただし、Decimalデータ型は、有効桁数の損失と表現の問題にもが、これらの問題は、はるかにまれです。Although the Decimal data type also has problems of representation and loss of precision, these issues are far less common.

• 中間値に近い値は切り捨てられますが期待がかどうかを判断する「ほぼ等しい」テストを実行するカスタムの丸め処理を行うアルゴリズムを定義します。Define a custom rounding algorithm that performs a "nearly equal" test to determine whether the value to be rounded is acceptably close to a midpoint value. 次の例では、定義、`RoundApproximate`小数部の値は、十分に中間丸め処理の対象に中間値の近くにあるかどうかを検査するメソッド。The following example defines a `RoundApproximate` method that examines whether a fractional value is sufficiently near to a midpoint value to be subject to midpoint rounding. 例の出力が示すように、前の例に示すように丸めの問題を修正します。As the output from the example shows, it corrects the rounding problem shown in the previous example.

``````using System;

public class Example
{
public static void Main()
{
Console.WriteLine("{0,5} {1,20:R}  {2,12} {3,15}\n",
"Value", "Full Precision", "ToEven",
"AwayFromZero");
double value = 11.1;
for (int ctr = 0; ctr <= 5; ctr++)

Console.WriteLine();

value = 11.5;
}

private static double RoundValueAndAdd(double value)
{
const double tolerance = 8e-14;

Console.WriteLine("{0,5:N1} {0,20:R}  {1,12} {2,15}",
value,
RoundApproximate(value, 0, tolerance, MidpointRounding.ToEven),
RoundApproximate(value, 0, tolerance, MidpointRounding.AwayFromZero));
return value + .1;
}

private static double RoundApproximate(double dbl, int digits, double margin,
MidpointRounding mode)
{
double fraction = dbl * Math.Pow(10, digits);
double value = Math.Truncate(fraction);
fraction = fraction - value;
if (fraction == 0)
return dbl;

double tolerance = margin * dbl;
// Determine whether this is a midpoint value.
if ((fraction >= .5 - tolerance) & (fraction <= .5 + tolerance)) {
if (mode == MidpointRounding.AwayFromZero)
return (value + 1)/Math.Pow(10, digits);
else
if (value % 2 != 0)
return (value + 1)/Math.Pow(10, digits);
else
return value/Math.Pow(10, digits);
}
// Any remaining fractional value greater than .5 is not a midpoint value.
if (fraction > .5)
return (value + 1)/Math.Pow(10, digits);
else
return value/Math.Pow(10, digits);
}
}
// The example displays the following output:
//       Value       Full Precision        ToEven    AwayFromZero
//
//        11.1                 11.1            11              11
//        11.2                 11.2            11              11
//        11.3   11.299999999999999            11              11
//        11.4   11.399999999999999            11              11
//        11.5   11.499999999999998            12              12
//        11.6   11.599999999999998            12              12
//
//        11.5                 11.5            12              12
``````
``````Module Example
Public Sub Main()
Dim value As Double = 11.1

Console.WriteLine("{0,5} {1,20:R}  {2,12} {3,15}\n",
"Value", "Full Precision", "ToEven",
"AwayFromZero")
For ctr As Integer = 0 To 5
Next
Console.WriteLine()

value = 11.5
End Sub

Private Function RoundValueAndAdd(value As Double) As Double
Const tolerance As Double = 8e-14
Console.WriteLine("{0,5:N1} {0,20:R}  {1,12} {2,15}",
value,
RoundApproximate(value, 0, tolerance, MidpointRounding.ToEven),
RoundApproximate(value, 0, tolerance, MidpointRounding.AwayFromZero))
Return value + .1
End Function

Private Function RoundApproximate(dbl As Double, digits As Integer, margin As Double,
mode As MidpointRounding) As Double
Dim fraction As Double = dbl * Math.Pow(10, digits)
Dim value As Double = Math.Truncate(fraction)
fraction = fraction - value
If fraction = 0 Then Return dbl

Dim tolerance As Double = margin * dbl
' Determine whether this is a midpoint value.
If (fraction >= .5 - tolerance) And (fraction <= .5 + tolerance) Then
If mode = MidpointRounding.AwayFromZero Then
Return (value + 1)/Math.Pow(10, digits)
Else
If value Mod 2 <> 0 Then
Return (value + 1)/Math.Pow(10, digits)
Else
Return value/Math.Pow(10, digits)
End If
End If
End If
' Any remaining fractional value greater than .5 is not a midpoint value.
If fraction > .5 Then
Return (value + 1)/Math.Pow(10, digits)
Else
return value/Math.Pow(10, digits)
End If
End Function
End Module
' The example displays the following output:
'       Value       Full Precision        ToEven    AwayFromZero
'
'        11.1                 11.1            11              11
'        11.2                 11.2            11              11
'        11.3   11.299999999999999            11              11
'        11.4   11.399999999999999            11              11
'        11.5   11.499999999999998            12              12
'        11.6   11.599999999999998            12              12
'
'        11.5                 11.5            12              12
``````

#### 丸めと単精度浮動小数点値Rounding and single-precision floating-point values

Roundメソッドには、型の引数を受け入れるオーバー ロードが含まれています。DecimalDoubleします。The Round method includes overloads that accept arguments of type Decimal and Double. 型の値を丸めるメソッドがないSingleします。There are no methods that round values of type Single. 渡す場合、Singleのオーバー ロードのいずれかに値、Roundキャスト (C#) は、メソッド、または変換 (Visual Basic) で、 Double、および対応するRoundオーバー ロードをDoubleパラメーターと呼びます。If you pass a Single value to one of the overloads of the Round method, it is cast (in C#) or converted (in Visual Basic) to a Double, and the corresponding Round overload with a Double parameter is called. 拡大変換ですが、多くの場合が、精度の損失次の例に示すようにします。Although this is a widening conversion, it often involves a loss of precision, as the following example illustrates. ときに、Singleに 16.325 の値が渡される、Roundメソッドされ、結果は 16.32 の 16.33、いない期待される結果を最も近い規則への丸めを使用して 2 つの小数点以下桁数に丸められます、します。When a Single value of 16.325 is passed to the Round method and rounded to two decimal places using the rounding to nearest convention, the result is 16.33 and not the expected result of 16.32.

``````using System;

public class Example
{
public static void Main()
{
Single value = 16.325f;
Console.WriteLine("Widening Conversion of {0:R} (type {1}) to {2:R} (type {3}): ",
value, value.GetType().Name, (double) value,
((double) (value)).GetType().Name);
Console.WriteLine(Math.Round(value, 2));
Console.WriteLine(Math.Round(value, 2, MidpointRounding.AwayFromZero));
Console.WriteLine();

Decimal decValue = (decimal) value;
Console.WriteLine("Cast of {0:R} (type {1}) to {2} (type {3}): ",
value, value.GetType().Name, decValue,
decValue.GetType().Name);
Console.WriteLine(Math.Round(decValue, 2));
Console.WriteLine(Math.Round(decValue, 2, MidpointRounding.AwayFromZero));
}
}
// The example displays the following output:
//    Widening Conversion of 16.325 (type Single) to 16.325000762939453 (type Double):
//    16.33
//    16.33
//
//    Cast of 16.325 (type Single) to 16.325 (type Decimal):
//    16.32
//    16.33
``````
``````Module Example
Public Sub Main()
Dim value As Single = 16.325
Console.WriteLine("Widening Conversion of {0:R} (type {1}) to {2:R} (type {3}): ",
value, value.GetType().Name, CDbl(value),
CDbl(value).GetType().Name)
Console.WriteLine(Math.Round(value, 2))
Console.WriteLine(Math.Round(value, 2, MidpointRounding.AwayFromZero))
Console.WriteLine()

Dim decValue As Decimal = CDec(value)
Console.WriteLine("Cast of {0:R} (type {1}) to {2} (type {3}): ",
value, value.GetType().Name, decValue,
decValue.GetType().Name)
Console.WriteLine(Math.Round(decValue, 2))
Console.WriteLine(Math.Round(decValue, 2, MidpointRounding.AwayFromZero))
Console.WriteLine()
End Sub
End Module
' The example displays the following output:
'    Widening Conversion of 16.325 (type Single) to 16.325000762939453 (type Double):
'    16.33
'    16.33
'
'    Cast of 16.325 (type Single) to 16.325 (type Decimal):
'    16.32
'    16.33
``````

この予期しない結果での変換で精度の損失、Single値をDoubleします。This unexpected result is due to a loss of precision in the conversion of the Single value to a Double. その結果Doubleは上方向に丸められます常に、16.325000762939453 の値の中間値でないし、16.325 より大きい。Because the resulting Double value of 16.325000762939453 is not a midpoint value and is greater than 16.325, it is always rounded upward.

##

## Round(Decimal, Int32, MidpointRounding)Round(Decimal, Int32, MidpointRounding)Round(Decimal, Int32, MidpointRounding)Round(Decimal, Int32, MidpointRounding)

10 進数の値は指定した小数部の桁数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a decimal value to a specified number of fractional digits, and uses the specified rounding convention for midpoint values.

``````public:
static System::Decimal Round(System::Decimal d, int decimals, MidpointRounding mode);``````
``public static decimal Round (decimal d, int decimals, MidpointRounding mode);``
``static member Round : decimal * int * MidpointRounding -> decimal``
``Public Shared Function Round (d As Decimal, decimals As Integer, mode As MidpointRounding) As Decimal``

#### パラメーター

d
Decimal Decimal Decimal Decimal

decimals
Int32 Int32 Int32 Int32

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

`d` が 2 つの数値の中間にある場合に丸める方法を指定します。Specification for how to round `d` if it is midway between two other numbers.

#### 戻り値

`d` に等しい小数部の桁数を格納する `decimals` に最も近い数値。The number nearest to `d` that contains a number of fractional digits equal to `decimals`. `d` の小数部の桁数が `decimals` よりも少ない場合、`d` がそのまま返されます。If `d` has fewer fractional digits than `decimals`, `d` is returned unchanged.

#### 例外

`decimals` が 0 未満か、28 を超えています。`decimals` is less than 0 or greater than 28.

`mode`MidpointRounding の正しい値ではありません。`mode` is not a valid value of MidpointRounding.

### 例Example

``````// This example demonstrates the Math.Round() method in conjunction
// with the MidpointRounding enumeration.
using namespace System;

void main()
{
Decimal result = (Decimal) 0.0;
Decimal posValue = (Decimal) 3.45;
Decimal negValue = (Decimal) -3.45;

// By default, round a positive and a negative value to the nearest
// even number. The precision of the result is 1 decimal place.
result = Math::Round(posValue, 1);
Console::WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue);
result = Math::Round(negValue, 1);
Console::WriteLine("{0,4} = Math.Round({1,5}, 1)", result, negValue);
Console::WriteLine();

// Round a positive value to the nearest even number, then to the
// nearest number away from zero. The precision of the result is 1
// decimal place.
result = Math::Round(posValue, 1, MidpointRounding::ToEven);
Console::WriteLine(
"{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, posValue);
result = Math::Round(posValue, 1, MidpointRounding::AwayFromZero);
Console::WriteLine(
"{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)",
result, posValue);
Console::WriteLine();

// Round a negative value to the nearest even number, then to the
// nearest number away from zero. The precision of the result is 1
// decimal place.
result = Math::Round(negValue, 1, MidpointRounding::ToEven);
Console::WriteLine(
"{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, negValue);
result = Math::Round(negValue, 1, MidpointRounding::AwayFromZero);
Console::WriteLine(
"{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)",
result, negValue);
Console::WriteLine();
}

/*
This code example produces the following results:

3.4 = Math.Round( 3.45, 1)
-3.4 = Math.Round(-3.45, 1)

3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)

-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)

*/
``````
``````// This example demonstrates the Math.Round() method in conjunction
// with the MidpointRounding enumeration.
using System;

class Sample
{
public static void Main()
{
decimal result = 0.0m;
decimal posValue =  3.45m;
decimal negValue = -3.45m;

// By default, round a positive and a negative value to the nearest even number.
// The precision of the result is 1 decimal place.

result = Math.Round(posValue, 1);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue);
result = Math.Round(negValue, 1);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, negValue);
Console.WriteLine();

// Round a positive value to the nearest even number, then to the nearest number away from zero.
// The precision of the result is 1 decimal place.

result = Math.Round(posValue, 1, MidpointRounding.ToEven);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", result, posValue);
result = Math.Round(posValue, 1, MidpointRounding.AwayFromZero);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", result, posValue);
Console.WriteLine();

// Round a negative value to the nearest even number, then to the nearest number away from zero.
// The precision of the result is 1 decimal place.

result = Math.Round(negValue, 1, MidpointRounding.ToEven);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", result, negValue);
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", result, negValue);
Console.WriteLine();
}
}
/*
This code example produces the following results:

3.4 = Math.Round( 3.45, 1)
-3.4 = Math.Round(-3.45, 1)

3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)

-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)

*/
``````
``````' This example demonstrates the Math.Round() method in conjunction
' with the MidpointRounding enumeration.
Imports System

Class Sample
Public Shared Sub Main()
Dim result As Decimal = 0D
Dim posValue As Decimal = 3.45D
Dim negValue As Decimal = -3.45D

' By default, round a positive and a negative value to the nearest even number.
' The precision of the result is 1 decimal place.
result = Math.Round(posValue, 1)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue)
result = Math.Round(negValue, 1)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, negValue)
Console.WriteLine()

' Round a positive value to the nearest even number, then to the nearest number
' away from zero. The precision of the result is 1 decimal place.
result = Math.Round(posValue, 1, MidpointRounding.ToEven)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", _
result, posValue)
result = Math.Round(posValue, 1, MidpointRounding.AwayFromZero)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", _
result, posValue)
Console.WriteLine()

' Round a negative value to the nearest even number, then to the nearest number
' away from zero. The precision of the result is 1 decimal place.
result = Math.Round(negValue, 1, MidpointRounding.ToEven)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)", _
result, negValue)
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)", _
result, negValue)
Console.WriteLine()

End Sub 'Main
End Class 'Sample
'
'This code example produces the following results:
'
' 3.4 = Math.Round( 3.45, 1)
'-3.4 = Math.Round(-3.45, 1)
'
' 3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
' 3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
'
'-3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
'-3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
'
``````
こちらもご覧ください

## Round(Double, Int32, MidpointRounding)Round(Double, Int32, MidpointRounding)Round(Double, Int32, MidpointRounding)Round(Double, Int32, MidpointRounding)

``````public:
static double Round(double value, int digits, MidpointRounding mode);``````
``public static double Round (double value, int digits, MidpointRounding mode);``
``static member Round : double * int * MidpointRounding -> double``
``Public Shared Function Round (value As Double, digits As Integer, mode As MidpointRounding) As Double``

#### パラメーター

value
Double Double Double Double

digits
Int32 Int32 Int32 Int32

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

`value` が 2 つの数値の中間にある場合に丸める方法を指定します。Specification for how to round `value` if it is midway between two other numbers.

#### 戻り値

`digits` に等しい小数部の桁数を格納する `value` に最も近い数値。The number nearest to `value` that has a number of fractional digits equal to `digits`. `value` の小数部の桁数が `digits` よりも少ない場合、`value` がそのまま返されます。If `value` has fewer fractional digits than `digits`, `value` is returned unchanged.

#### 例外

`digits` が 0 より小さいか、15 を超えています。`digits` is less than 0 or greater than 15.

`mode`MidpointRounding の正しい値ではありません。`mode` is not a valid value of MidpointRounding.

### 例Example

``````using System;

class Sample
{
public static void Main()
{
double posValue =  3.45;
double negValue = -3.45;

// Round a positive and a negative value using the default.
double result = Math.Round(posValue, 1);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue);
result = Math.Round(negValue, 1);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)\n", result, negValue);

// Round a positive value using a MidpointRounding value.
result = Math.Round(posValue, 1, MidpointRounding.ToEven);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, posValue);
result = Math.Round(posValue, 1, MidpointRounding.AwayFromZero);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)\n",
result, posValue);

// Round a negative value using a MidpointRounding value.
result = Math.Round(negValue, 1, MidpointRounding.ToEven);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, negValue);
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero);
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)\n",
result, negValue);
}
}
// The example displays the following output:
//        3.4 = Math.Round( 3.45, 1)
//       -3.4 = Math.Round(-3.45, 1)
//
//        3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
//        3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
//
//       -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
//       -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
``````
``````Module Example
Public Sub Main()
Dim posValue As Double = 3.45
Dim negValue As Double = -3.45

' Round a positive and a negative value using the default.
Dim result As Double = Math.Round(posValue, 1)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, posValue)
result = Math.Round(negValue, 1)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1)", result, negValue)
Console.WriteLine()

' Round a positive value using a MidpointRounding value.
result = Math.Round(posValue, 1, MidpointRounding.ToEven)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, posValue)
result = Math.Round(posValue, 1, MidpointRounding.AwayFromZero)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)",
result, posValue)
Console.WriteLine()

' Round a positive value using a MidpointRounding value.
result = Math.Round(negValue, 1, MidpointRounding.ToEven)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.ToEven)",
result, negValue)
result = Math.Round(negValue, 1, MidpointRounding.AwayFromZero)
Console.WriteLine("{0,4} = Math.Round({1,5}, 1, MidpointRounding.AwayFromZero)",
result, negValue)
Console.WriteLine()
End Sub
End Module
' The example displays the following output:
'       3.4 = Math.Round( 3.45, 1)
'       -3.4 = Math.Round(-3.45, 1)
'
'       3.4 = Math.Round( 3.45, 1, MidpointRounding.ToEven)
'       3.5 = Math.Round( 3.45, 1, MidpointRounding.AwayFromZero)
'
'       -3.4 = Math.Round(-3.45, 1, MidpointRounding.ToEven)
'       -3.5 = Math.Round(-3.45, 1, MidpointRounding.AwayFromZero)
``````

### 注意 (呼び出し元)

[!code-csharpSystem.Math.Round#3] [!code-vbSystem.Math.Round#3][!code-csharpSystem.Math.Round#3] [!code-vbSystem.Math.Round#3]

こちらもご覧ください

## Round(Double, MidpointRounding)Round(Double, MidpointRounding)Round(Double, MidpointRounding)Round(Double, MidpointRounding)

``````public:
static double Round(double value, MidpointRounding mode);``````
``public static double Round (double value, MidpointRounding mode);``
``static member Round : double * MidpointRounding -> double``
``Public Shared Function Round (value As Double, mode As MidpointRounding) As Double``

#### パラメーター

value
Double Double Double Double

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

`value` が 2 つの数値の中間にある場合に丸める方法を指定します。Specification for how to round `value` if it is midway between two other numbers.

#### 戻り値

`value` に最も近い整数。The integer nearest `value`. `value` が 2 つの整数 (一方が偶数でもう一方が奇数) の中間にある場合、`mode` によって 2 つの数値のどちらが返されるかが決まります。If `value` is halfway between two integers, one of which is even and the other odd, then `mode` determines which of the two is returned. このメソッドは、整数型ではなく Double を返します。Note that this method returns a Double instead of an integral type.

#### 例外

`mode`MidpointRounding の正しい値ではありません。`mode` is not a valid value of MidpointRounding.

### 例Example

``````using System;

public class Example
{
public static void Main()
{
Double[] values = { 12.0, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6,
12.7, 12.8, 12.9, 13.0 };
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}", "Value", "Default",
"ToEven", "AwayFromZero");
foreach (var value in values)
Console.WriteLine("{0,-10:R} {1,-10} {2,-10} {3,-15}",
value, Math.Round(value),
Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero));
}
}
// The example displays the following output:
//       Value      Default    ToEven     AwayFromZero
//       12         12         12         12
//       12.1       12         12         12
//       12.2       12         12         12
//       12.3       12         12         12
//       12.4       12         12         12
//       12.5       12         12         13
//       12.6       13         13         13
//       12.7       13         13         13
//       12.8       13         13         13
//       12.9       13         13         13
//       13.0       13         13         13
``````
``````Module Example
Public Sub Main()
Dim values() As Double = { 12.0, 12.1, 12.2, 12.3, 12.4, 12.5, 12.6,
12.7, 12.8, 12.9, 13.0 }
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}", "Value", "Default",
"ToEven", "AwayFromZero")
For Each value In values
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}",
value, Math.Round(value),
Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero))
Next
End Sub
End Module
' The example displays the following output:
'       Value      Default    ToEven     AwayFromZero
'       12         12         12         12
'       12.1       12         12         12
'       12.2       12         12         12
'       12.3       12         12         12
'       12.4       12         12         12
'       12.5       12         12         13
'       12.6       13         13         13
'       12.7       13         13         13
'       12.8       13         13         13
'       12.9       13         13         13
'       13.0       13         13         13
``````

### 注意 (呼び出し元)

[!code-csharp-interactiveSystem.Math.Round#4] [!code-vbSystem.Math.Round#4][!code-csharp-interactiveSystem.Math.Round#4] [!code-vbSystem.Math.Round#4]

こちらもご覧ください

## Round(Double, Int32)Round(Double, Int32)Round(Double, Int32)Round(Double, Int32)

``````public:
static double Round(double value, int digits);``````
``public static double Round (double value, int digits);``
``static member Round : double * int -> double``
``Public Shared Function Round (value As Double, digits As Integer) As Double``

#### パラメーター

value
Double Double Double Double

digits
Int32 Int32 Int32 Int32

#### 戻り値

`value` に等しい小数部の桁数を格納する `digits` に最も近い数値。The number nearest to `value` that contains a number of fractional digits equal to `digits`.

#### 例外

`digits` が 0 より小さいか、15 を超えています。`digits` is less than 0 or greater than 15.

### 注釈

このメソッドは、既定の規約の丸め処理を行うMidpointRounding.ToEvenします。This method uses the default rounding convention of MidpointRounding.ToEven. 参照してください中間値と丸め規則中間値を持つ数値丸め処理を行う方法についてはします。See Midpoint values and rounding conventions for information about rounding numbers with midpoint values.

### 例Example

``````Math::Round(3.44, 1); //Returns 3.4.
Math::Round(3.45, 1); //Returns 3.4.
Math::Round(3.46, 1); //Returns 3.5.

Math::Round(4.34, 1); // Returns 4.3
Math::Round(4.35, 1); // Returns 4.4
Math::Round(4.36, 1); // Returns 4.4
``````
``````Math.Round(3.44, 1); //Returns 3.4.
Math.Round(3.45, 1); //Returns 3.4.
Math.Round(3.46, 1); //Returns 3.5.

Math.Round(4.34, 1); // Returns 4.3
Math.Round(4.35, 1); // Returns 4.4
Math.Round(4.36, 1); // Returns 4.4
``````
``````Math.Round(3.44, 1) 'Returns 3.4.
Math.Round(3.45, 1) 'Returns 3.4.
Math.Round(3.46, 1) 'Returns 3.5.

Math.Round(4.34, 1) ' Returns 4.3
Math.Round(4.35, 1) ' Returns 4.4
Math.Round(4.36, 1) ' Returns 4.4
``````

### 注意 (呼び出し元)

[!code-csharp-interactiveSystem.Math.Round#2] [!code-vbSystem.Math.Round#2][!code-csharp-interactiveSystem.Math.Round#2] [!code-vbSystem.Math.Round#2]

こちらもご覧ください

## Round(Double)Round(Double)Round(Double)Round(Double)

``````public:
static double Round(double a);``````
``public static double Round (double a);``
``static member Round : double -> double``
``Public Shared Function Round (a As Double) As Double``

#### パラメーター

a
Double Double Double Double

#### 戻り値

`a` に最も近い整数。The integer nearest `a`. `a` の小数部が 2 つの整数 (一方が偶数で、もう一方が奇数) の中間にある場合は、偶数が返されます。If the fractional component of `a` is halfway between two integers, one of which is even and the other odd, then the even number is returned. このメソッドは、整数型ではなく Double を返します。Note that this method returns a Double instead of an integral type.

### 注釈

このメソッドは、既定の規約の丸め処理を行うMidpointRounding.ToEvenします。This method uses the default rounding convention of MidpointRounding.ToEven. 参照してください中間値と丸め規則中間値を持つ数値丸め処理を行う方法についてはします。See Midpoint values and rounding conventions for information about rounding numbers with midpoint values.

Visual Basic 15.8 から始めてにによって返される値を渡す場合、double 型から整数型に変換のパフォーマンスは最適化は、`Round`メソッドのいずれかを整数変換関数、または double 型の値によって返される`Round`を整数に変換が自動的にOption Strictオフ に設定します。Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the `Round` method to the any of the integral conversion functions, or if the Double value returned by `Round` is automatically converted to an integer with Option Strict set to Off. この最適化によって、コードをより速く実行できます。大きい数値の整数型への変換を行うコードでは、最大で 2 倍速くなります。This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. 次の例は、このような最適化された変換を示しています。The following example illustrates such optimized conversions:

``````Dim d1 As Double = 1043.75133
Dim i1 As Integer = CInt(Math.Ceiling(d1))        ' Result: 1044

Dim d2 As Double = 7968.4136
Dim i2 As Integer = CInt(Math.Ceiling(d2))        ' Result: 7968
``````

### 例Example

``````using namespace System;

void main()
{
Console::WriteLine("Classic Math.Round in CPP");
Console::WriteLine(Math::Round(4.4));     // 4
Console::WriteLine(Math::Round(4.5));     // 4
Console::WriteLine(Math::Round(4.6));     // 5
Console::WriteLine(Math::Round(5.5));     // 6
}
``````
``````using System;

class Program
{
static void Main()
{
Console.WriteLine("Classic Math.Round in CSharp");
Console.WriteLine(Math.Round(4.4)); // 4
Console.WriteLine(Math.Round(4.5)); // 4
Console.WriteLine(Math.Round(4.6)); // 5
Console.WriteLine(Math.Round(5.5)); // 6
}
}
``````
``````Imports System

Module Module1

Sub Main()
Console.WriteLine("Classic Math.Round in Visual Basic")
Console.WriteLine(Math.Round(4.4)) ' 4
Console.WriteLine(Math.Round(4.5)) ' 4
Console.WriteLine(Math.Round(4.6)) ' 5
Console.WriteLine(Math.Round(5.5)) ' 6
End Sub

End Module
``````

### 注意 (呼び出し元)

[!code-csharpSystem.Math.Round#1] [!code-vbSystem.Math.Round#1][!code-csharpSystem.Math.Round#1] [!code-vbSystem.Math.Round#1]

こちらもご覧ください

## Round(Decimal, Int32)Round(Decimal, Int32)Round(Decimal, Int32)Round(Decimal, Int32)

10 進数の値は指定した小数部の桁数に丸められ、中間値は最も近い偶数値に丸められます。Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.

``````public:
static System::Decimal Round(System::Decimal d, int decimals);``````
``public static decimal Round (decimal d, int decimals);``
``static member Round : decimal * int -> decimal``
``Public Shared Function Round (d As Decimal, decimals As Integer) As Decimal``

#### パラメーター

d
Decimal Decimal Decimal Decimal

decimals
Int32 Int32 Int32 Int32

#### 戻り値

`d` に等しい小数部の桁数を格納する `decimals` に最も近い数値。The number nearest to `d` that contains a number of fractional digits equal to `decimals`.

#### 例外

`decimals` が 0 未満か、28 を超えています。`decimals` is less than 0 or greater than 28.

### 注釈

このメソッドは、既定の規約の丸め処理を行うMidpointRounding.ToEvenします。This method uses the default rounding convention of MidpointRounding.ToEven. 参照してください中間値と丸め規則中間値を持つ数値丸め処理を行う方法についてはします。See Midpoint values and rounding conventions for information about rounding numbers with midpoint values.

### 例Example

``````using System;

public class Sample {
static void Main() {
Console.WriteLine(Math.Round(3.44m, 1));
Console.WriteLine(Math.Round(3.45m, 1));
Console.WriteLine(Math.Round(3.46m, 1));
Console.WriteLine();

Console.WriteLine(Math.Round(4.34m, 1));
Console.WriteLine(Math.Round(4.35m, 1));
Console.WriteLine(Math.Round(4.36m, 1));
}
}
// The example displays the following output:
//       3.4
//       3.4
//       3.5
//
//       4.3
//       4.4
//       4.4
``````
``````Public Module Example
Sub Main()
Console.WriteLine(Math.Round(3.44, 1))
Console.WriteLine(Math.Round(3.45, 1))
Console.WriteLine(Math.Round(3.46, 1))
Console.WriteLine()

Console.WriteLine(Math.Round(4.34, 1))
Console.WriteLine(Math.Round(4.35, 1))
Console.WriteLine(Math.Round(4.36, 1))
End Sub
End Module
' The example displays the following output:
'       3.4
'       3.4
'       3.5
'
'       4.3
'       4.4
'       4.4
``````
こちらもご覧ください

## Round(Decimal)Round(Decimal)Round(Decimal)Round(Decimal)

10 進数の値は最も近い整数値に丸められ、中間値は最も近い偶数値に丸められます。Rounds a decimal value to the nearest integral value, and rounds midpoint values to the nearest even number.

``````public:
static System::Decimal Round(System::Decimal d);``````
``public static decimal Round (decimal d);``
``static member Round : decimal -> decimal``
``Public Shared Function Round (d As Decimal) As Decimal``

#### パラメーター

d
Decimal Decimal Decimal Decimal

#### 戻り値

`d` パラメーターに最も近い整数。The integer nearest the `d` parameter. `d` の小数部が 2 つの整数 (一方が偶数で、もう一方が奇数) の中間にある場合は、偶数が返されます。If the fractional component of `d` is halfway between two integers, one of which is even and the other odd, the even number is returned. このメソッドは、整数型ではなく Decimal を返します。Note that this method returns a Decimal instead of an integral type.

### 注釈

このメソッドは、既定の規約の丸め処理を行うMidpointRounding.ToEvenします。This method uses the default rounding convention of MidpointRounding.ToEven. 参照してください中間値と丸め規則中間値を持つ数値丸め処理を行う方法についてはします。See Midpoint values and rounding conventions for information about rounding numbers with midpoint values.

### 例Example

``````using System;

class Example
{
static void Main()
{
for (decimal value = 4.2m; value <= 4.8m; value+=.1m )
Console.WriteLine("{0} --> {1}", value, Math.Round(value));
}
}
// The example displays the following output:
//       4.2 --> 4
//       4.3 --> 4
//       4.4 --> 4
//       4.5 --> 4
//       4.6 --> 5
//       4.7 --> 5
//       4.8 --> 5
``````
``````Module Example
Public Sub Main()
For value As Decimal = 4.2d To 4.8d Step .1d
Console.WriteLine("{0} --> {1}", value, Math.Round(value))
Next
End Sub
End Module
' The example displays the following output:
'       4.2 --> 4
'       4.3 --> 4
'       4.4 --> 4
'       4.5 --> 4
'       4.6 --> 5
'       4.7 --> 5
'       4.8 --> 5
``````
こちらもご覧ください

## Round(Decimal, MidpointRounding)Round(Decimal, MidpointRounding)Round(Decimal, MidpointRounding)Round(Decimal, MidpointRounding)

10 進数の値は最も近い整数に丸められ、中間値には指定した丸め処理が使用されます。Rounds a decimal value to the nearest integer, and uses the specified rounding convention for midpoint values.

``````public:
static System::Decimal Round(System::Decimal d, MidpointRounding mode);``````
``public static decimal Round (decimal d, MidpointRounding mode);``
``static member Round : decimal * MidpointRounding -> decimal``
``Public Shared Function Round (d As Decimal, mode As MidpointRounding) As Decimal``

#### パラメーター

d
Decimal Decimal Decimal Decimal

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

`d` が 2 つの数値の中間にある場合に丸める方法を指定します。Specification for how to round `d` if it is midway between two other numbers.

#### 戻り値

`d` に最も近い整数。The integer nearest `d`. `d` が 2 つの数値 (一方が偶数でもう一方が奇数) の中間にある場合、`mode` によって 2 つの数値のどちらが返されるかが決まります。If `d` is halfway between two numbers, one of which is even and the other odd, then `mode` determines which of the two is returned. このメソッドは、整数型ではなく Decimal を返します。Note that this method returns a Decimal instead of an integral type.

#### 例外

`mode`MidpointRounding の正しい値ではありません。`mode` is not a valid value of MidpointRounding.

### 例Example

``````using System;

public class Example
{
public static void Main()
{
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}", "Value", "Default",
"ToEven", "AwayFromZero");
for (decimal value = 12.0m; value <= 13.0m; value += 0.1m)
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}",
value, Math.Round(value),
Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero));
}
}
// The example displays the following output:
//       Value      Default    ToEven     AwayFromZero
//       12         12         12         12
//       12.1       12         12         12
//       12.2       12         12         12
//       12.3       12         12         12
//       12.4       12         12         12
//       12.5       12         12         13
//       12.6       13         13         13
//       12.7       13         13         13
//       12.8       13         13         13
//       12.9       13         13         13
//       13.0       13         13         13
``````
``````Module Example
Public Sub Main()
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}", "Value", "Default",
"ToEven", "AwayFromZero")
For value As Decimal = 12.0d To 13.0d Step .1d
Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-15}",
value, Math.Round(value),
Math.Round(value, MidpointRounding.ToEven),
Math.Round(value, MidpointRounding.AwayFromZero))
Next
End Sub
End Module
' The example displays the following output:
'       Value      Default    ToEven     AwayFromZero
'       12         12         12         12
'       12.1       12         12         12
'       12.2       12         12         12
'       12.3       12         12         12
'       12.4       12         12         12
'       12.5       12         12         13
'       12.6       13         13         13
'       12.7       13         13         13
'       12.8       13         13         13
'       12.9       13         13         13
'       13.0       13         13         13
``````
こちらもご覧ください