Decimal.Round Decimal.Round Decimal.Round Decimal.Round Method

定義

最も近い整数または指定した小数点数に値を丸めます。 Rounds a value to the nearest integer or specified number of decimal places.

オーバーロード

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

10 進値を最も近い整数に丸めます。 Rounds a decimal value to the nearest integer.

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

Decimal 値を、指定した小数点以下の桁数に丸めます。 Rounds a Decimal value to a specified number of decimal places.

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

10 進値を最も近い整数に丸めます。 Rounds a decimal value to the nearest integer. パラメーターは、値が他の 2 つの数値の中間にある場合にその値を丸める方法を指定します。 A parameter specifies how to round the value if it is midway between two other numbers.

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

10 進値を指定した精度に丸めます。 Rounds a decimal value to a specified precision. パラメーターは、値が他の 2 つの数値の中間にある場合にその値を丸める方法を指定します。 A parameter specifies how to round the value if it is midway between two other numbers.

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

10 進値を最も近い整数に丸めます。 Rounds a decimal value to the nearest integer.

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

丸め対象の 10 進数。 A decimal number to round.

戻り値

d パラメーターの値に最も近い整数。 The integer that is nearest to the d parameter. d が 2 つの整数 (一方が偶数でもう一方が奇数) の中間にある場合は偶数が返されます。 If d is halfway between two integers, one of which is even and the other odd, the even number is returned.

例外

結果は Decimal 値の範囲外です。 The result is outside the range of a Decimal value.

次の例の範囲に丸めますDecimalで 100 ~ 102 を最も近い整数値。The following example rounds a range of Decimal values between 100 and 102 to the nearest integer. メソッドは、銀行型丸めを使用しているために、100.5 が 102 を 100 と 101.5 ラウンドに丸めることに注意してください。Because the method uses banker's rounding, note that 100.5 rounds to 100 and 101.5 rounds to 102.

using System;

public class Example
{
   public static void Main()
   {
      for (decimal value = 100m; value <= 102m; value += .1m)
         Console.WriteLine("{0} --> {1}", value, Decimal.Round(value));

   }
}
// The example displays the following output:
//     100 --> 100
//     100.1 --> 100
//     100.2 --> 100
//     100.3 --> 100
//     100.4 --> 100
//     100.5 --> 100
//     100.6 --> 101
//     100.7 --> 101
//     100.8 --> 101
//     100.9 --> 101
//     101.0 --> 101
//     101.1 --> 101
//     101.2 --> 101
//     101.3 --> 101
//     101.4 --> 101
//     101.5 --> 102
//     101.6 --> 102
//     101.7 --> 102
//     101.8 --> 102
//     101.9 --> 102
//     102.0 --> 102
Module Example
   Public Sub Main()
      For value As Decimal = 100d To 102d Step .1d
         Console.WriteLine("{0} --> {1}", value, Decimal.Round(value))
      Next
   End Sub
End Module
' The example displays the following output:
'     100 --> 100
'     100.1 --> 100
'     100.2 --> 100
'     100.3 --> 100
'     100.4 --> 100
'     100.5 --> 100
'     100.6 --> 101
'     100.7 --> 101
'     100.8 --> 101
'     100.9 --> 101
'     101.0 --> 101
'     101.1 --> 101
'     101.2 --> 101
'     101.3 --> 101
'     101.4 --> 101
'     101.5 --> 102
'     101.6 --> 102
'     101.7 --> 102
'     101.8 --> 102
'     101.9 --> 102
'     102.0 --> 102

注釈

このメソッドの動作では、IEEE Standard 754、セクション 4 に従います。The behavior of this method follows IEEE Standard 754, section 4. このような丸めと呼びます半分もラウンドまたは銀行型丸めします。This kind of rounding is sometimes called round half to even or banker's rounding. 常に中間値を 1 つの方向に丸めるから発生する丸め誤差が最小限に抑えます。It minimizes rounding errors that result from consistently rounding a midpoint value in a single direction. 呼び出すことと同じである、Round(Decimal, MidpointRounding)メソッドをmodeの引数MidpointRounding.ToEvenします。It is equivalent to calling the Round(Decimal, MidpointRounding) method with a mode argument of MidpointRounding.ToEven.

こちらもご覧ください

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

Decimal 値を、指定した小数点以下の桁数に丸めます。 Rounds a Decimal value to a specified number of decimal places.

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

丸め対象の 10 進数。 A decimal number to round.

decimals
Int32 Int32 Int32 Int32

丸めた結果の数値の小数点以下の桁数を指定する 0 から 28 までの値。 A value from 0 to 28 that specifies the number of decimal places to round to.

戻り値

小数点以下の桁数 decimals に丸められた d と等価の 10 進数。 The decimal number equivalent to d rounded to decimals number of decimal places.

例外

decimals が 0 から 28 までの範囲内の値ではありません。 decimals is not a value from 0 to 28.

次の例がいくつかを丸めますDecimal値を指定した小数点以下桁数を使用して、Roundメソッド。The following example rounds several Decimal values to a specified number of decimal places using the Round method.

using System;

class Example
{
   public static void Main()
   {
      // Define a set of Decimal values.
      decimal[] values = { 1.45m, 1.55m, 123.456789m, 123.456789m, 
                           123.456789m, -123.456m, 
                           new Decimal(1230000000, 0, 0, true, 7 ),
                           new Decimal(1230000000, 0, 0, true, 7 ), 
                           -9999999999.9999999999m, 
                           -9999999999.9999999999m };
      // Define a set of integers to for decimals argument.
      int[] decimals = { 1, 1, 4, 6, 8, 0, 3, 11, 9, 10};
      
      Console.WriteLine("{0,26}{1,8}{2,26}", 
                        "Argument", "Digits", "Result" );
      Console.WriteLine("{0,26}{1,8}{2,26}", 
                        "--------", "------", "------" );
      for (int ctr = 0; ctr < values.Length; ctr++)
        Console.WriteLine("{0,26}{1,8}{2,26}", 
                          values[ctr], decimals[ctr], 
                          Decimal.Round(values[ctr], decimals[ctr]));
    }
}
// The example displays the following output:
//                   Argument  Digits                    Result
//                   --------  ------                    ------
//                       1.45       1                       1.4
//                       1.55       1                       1.6
//                 123.456789       4                  123.4568
//                 123.456789       6                123.456789
//                 123.456789       8                123.456789
//                   -123.456       0                      -123
//               -123.0000000       3                  -123.000
//               -123.0000000      11              -123.0000000
//     -9999999999.9999999999       9    -10000000000.000000000
//     -9999999999.9999999999      10    -9999999999.9999999999
Public Module Example
   Public Sub Main()
      ' Define a set of Decimal values.
      Dim values() As Decimal = { 1.45d, 1.55d, 123.456789d, 123.456789d, 
                                  123.456789d, -123.456d, 
                                  New Decimal(1230000000, 0, 0, true, 7 ),
                                  New Decimal(1230000000, 0, 0, true, 7 ), 
                                  -9999999999.9999999999d, 
                                  -9999999999.9999999999d }
      ' Define a set of integers to for decimals argument.
      Dim decimals() As Integer = { 1, 1, 4, 6, 8, 0, 3, 11, 9, 10}
      
      Console.WriteLine("{0,26}{1,8}{2,26}", 
                        "Argument", "Digits", "Result" )
      Console.WriteLine("{0,26}{1,8}{2,26}", 
                        "--------", "------", "------" )
      For ctr As Integer = 0 To values.Length - 1
        Console.WriteLine("{0,26}{1,8}{2,26}", 
                          values(ctr), decimals(ctr), 
                          Decimal.Round(values(ctr), decimals(ctr)))
      Next
   End Sub
End Module
' The example displays the following output:
'                   Argument  Digits                    Result
'                   --------  ------                    ------
'                       1.45       1                       1.4
'                       1.55       1                       1.6
'                 123.456789       4                  123.4568
'                 123.456789       6                123.456789
'                 123.456789       8                123.456789
'                   -123.456       0                      -123
'               -123.0000000       3                  -123.000
'               -123.0000000      11              -123.0000000
'     -9999999999.9999999999       9    -10000000000.000000000
'     -9999999999.9999999999      10    -9999999999.9999999999

注釈

このメソッドを呼び出すことは、Round(Decimal, Int32, MidpointRounding)メソッドをmodeの引数MidpointRounding.ToEvenします。ときにdちょうど中間には、結果は、偶数桁の小数部の右端の位置に丸められた値を 2 つの丸められた値。This method is equivalent to calling the Round(Decimal, Int32, MidpointRounding) method with a mode argument of MidpointRounding.ToEven.When d is exactly halfway between two rounded values, the result is the rounded value that has an even digit in the far right decimal position. たとえば、小数点以下 2 桁に丸められる場合、値 2.345 は 2.34 になり、値 2.355 は 2.36 になります。For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. このプロセスと呼ばれるでもへの丸め、または銀行型丸めします。This process is known as rounding toward even, or banker's rounding. 常に中間値を 1 つの方向に丸めるから発生する丸め誤差が最小限に抑えます。It minimizes rounding errors that result from consistently rounding a midpoint value in a single direction.

こちらもご覧ください

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

10 進値を最も近い整数に丸めます。 Rounds a decimal value to the nearest integer. パラメーターは、値が他の 2 つの数値の中間にある場合にその値を丸める方法を指定します。 A parameter specifies how to round the value if it is midway between two other numbers.

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

丸め対象の 10 進数。 A decimal number to round.

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

d が他の 2 つの数値の中間にある場合に丸める方法を指定する値。 A value that specifies how to round d if it is midway between two other numbers.

戻り値

d パラメーターの値に最も近い整数。 The integer that is nearest to the d parameter. d が 2 つの数値 (一方が偶数でもう一方が奇数) の中間にある場合、mode パラメーターで 2 つの数値のどちらを返すかを決定します。 If d is halfway between two numbers, one of which is even and the other odd, the mode parameter determines which of the two numbers is returned.

例外

結果が Decimal オブジェクトの範囲外です。 The result is outside the range of a Decimal object.

次の例は、によって返される値を表示、Round(Decimal)メソッド、Round(Decimal, MidpointRounding)メソッドをmodeの引数ToEven、およびRound(Decimal, MidpointRounding)メソッドをmodeの引数AwayFromZeroThe following example displays values returned by the Round(Decimal) method, the Round(Decimal, MidpointRounding) method with a mode argument of ToEven, and the Round(Decimal, MidpointRounding) method with a mode argument of AwayFromZero.

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

注釈

中間値では、結果の最下位の数字の後の値は、2 つの数値の間で正確に半分方法です。In a midpoint value, the value after the least significant digit in the result is precisely half way between two numbers. たとえば、7.5 は、整数に丸め 場合は、中間値です。For example, 7.5 is a midpoint value if it is to be rounded to an integer. 中間値は、最も近い値に簡単に識別できない丸め規則、によって指定されることがなく、mode引数。For midpoint values, the nearest value can't be easily identified without a rounding convention, which is specified by the mode argument. 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.5 が、たとえば、4 に丸められ、-4 に 5 回 4.5、-3.5 が丸められ、-4.5-5 に桁に丸めます。For example, 3.5 rounds to 4, 4.5 rounds to 5, -3.5 rounds to -4, and -4.5 rounds to -5. この形式の丸めがによって表される、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 even, or banker's rounding
中間値は、最も近い偶数に丸められます。Midpoint values are rounded to the nearest even number. たとえば、3.5 と 4.5 の両方が 4 に丸める、-3.5 と-4.5 の両方が-4 に丸めます。For example, both 3.5 and 4.5 round to 4, and both -3.5 and -4.5 round to -4. この形式の丸めがによって表される、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.

こちらもご覧ください

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

10 進値を指定した精度に丸めます。 Rounds a decimal value to a specified precision. パラメーターは、値が他の 2 つの数値の中間にある場合にその値を丸める方法を指定します。 A parameter specifies how to round the value if it is midway between two other numbers.

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

丸め対象の 10 進数。 A decimal number to round.

decimals
Int32 Int32 Int32 Int32

戻り値の小数点以下の有効桁数 (精度)。 The number of significant decimal places (precision) in the return value.

mode
MidpointRounding MidpointRounding MidpointRounding MidpointRounding

d が他の 2 つの数値の中間にある場合に丸める方法を指定する値。 A value that specifies how to round d if it is midway between two other numbers.

戻り値

decimals パラメーターと精度が等価である d パラメーターの値に最も近い数値。 The number that is nearest to the d parameter with a precision equal to the decimals parameter. d が 2 つの数値 (一方が偶数でもう一方が奇数) の中間にある場合、mode パラメーターで 2 つの数値のどちらを返すかを決定します。 If d is halfway between two numbers, one of which is even and the other odd, the mode parameter determines which of the two numbers is returned. d の精度が decimals より小さい場合、d は変更されずに返されます。 If the precision of d is less than decimals, d is returned unchanged.

例外

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

結果が Decimal オブジェクトの範囲外です。 The result is outside the range of a Decimal object.

次の例では、使用する方法、Round(Decimal, Int32, MidpointRounding)メソッドをMidpointRounding列挙体。The following example demonstrates how to use the Round(Decimal, Int32, MidpointRounding) method with the MidpointRounding enumeration.

// 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)
'

注釈

decimalsパラメーター戻り値の小数点以下桁数の大きな数を指定し、0 から 28 の範囲します。The decimals parameter specifies the number of significant decimal places in the return value and ranges from 0 to 28. 場合decimals0 の場合は、整数が返されます。If decimals is zero, an integer is returned.

中間値では、結果の最下位の数字の後の値は、2 つの数値の間で正確に半分方法です。In a midpoint value, the value after the least significant digit in the result is precisely half way between two numbers. たとえば、3.47500 は中間の値である場合に 2 つの小数点以下桁数が丸められます、7.500 中間値を整数に丸め 場合は、です。For example, 3.47500 is a midpoint value if it is to be rounded two decimal places, and 7.500 is a midpoint value if it is to be rounded to an integer. このような場合は、最も近い値に簡単に識別できない丸め規則、によって指定されることがなく、mode引数。In these cases, the nearest value can't be easily identified without a rounding convention, which is specified by the mode argument. Round(Decimal, Int32, MidpointRounding)メソッドは、中間値を処理するための 2 つの丸め規則をサポートしています。The Round(Decimal, Int32, MidpointRounding) 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 even, 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.

こちらもご覧ください

適用対象