次の方法で共有


Math.Min メソッド (Decimal, Decimal)

2 つの 10 進数のうち、小さい方を返します。

Overloads Public Shared Function Min( _
   ByVal val1 As Decimal, _   ByVal val2 As Decimal _) As Decimal
[C#]
public static decimal Min(decimalval1,decimalval2);
[C++]
public: static Decimal Min(Decimalval1,Decimalval2);
[JScript]
public static function Min(
   val1 : Decimal,val2 : Decimal) : Decimal;

パラメータ

  • val1
    比較する 2 つの Decimal 数の最初の数。
  • val2
    比較する 2 つの Decimal 数の 2 番目の数。

戻り値

パラメータ val1 または val2 のいずれか小さい方。

使用例

 
' This example demonstrates Math.Min()
Imports System

Class Sample
   Public Shared Sub Main()
      Dim str As String = "{0}: The lesser of {1,3} and {2,3} is {3}."
      Dim nl As String = Environment.NewLine
      
      Dim xByte1 As Byte = 1
      Dim xByte2 As Byte = 51
      Dim xShort1 As Short = - 2
      Dim xShort2 As Short = 52
      Dim xInt1 As Integer = - 3
      Dim xInt2 As Integer = 53
      Dim xLong1 As Long = - 4
      Dim xLong2 As Long = 54
      Dim xSingle1 As Single = 5F
      Dim xSingle2 As Single = 55F
      Dim xDouble1 As Double = 6.0
      Dim xDouble2 As Double = 56.0
      Dim xDecimal1 As [Decimal] = 7D
      Dim xDecimal2 As [Decimal] = 57D
      
      ' The following types are not CLS-compliant: SByte, UInt16, UInt32, and UInt64.
      
      Console.WriteLine("{0}Display the lesser of two values:{0}", nl)
      Console.WriteLine(str, "Byte   ", xByte1, xByte2, Math.Min(xByte1, xByte2))
      Console.WriteLine(str, "Int16  ", xShort1, xShort2, Math.Min(xShort1, xShort2))
      Console.WriteLine(str, "Int32  ", xInt1, xInt2, Math.Min(xInt1, xInt2))
      Console.WriteLine(str, "Int64  ", xLong1, xLong2, Math.Min(xLong1, xLong2))
      Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2))
      Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2))
      Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2))
      '
      Console.Write("{0}The following types are not supported: ", nl)
      Console.WriteLine("SByte, UInt16, UInt32, and UInt64.")
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Display the lesser of two values:
'
'Byte   : The lesser of   1 and  51 is 1.
'Int16  : The lesser of  -2 and  52 is -2.
'Int32  : The lesser of  -3 and  53 is -3.
'Int64  : The lesser of  -4 and  54 is -4.
'Single : The lesser of   5 and  55 is 5.
'Double : The lesser of   6 and  56 is 6.
'Decimal: The lesser of   7 and  57 is 7.
'
'The following types are not supported: SByte, UInt16, UInt32, and UInt64.
'

[C#] 
// This example demonstrates Math.Min()
using System;

class Sample 
{
    public static void Main() 
    {
    string str = "{0}: The lesser of {1,3} and {2,3} is {3}.";
    string nl = Environment.NewLine;

    byte     xByte1    = 1,    xByte2    = 51;    
    short    xShort1   = -2,   xShort2   = 52;
    int      xInt1     = -3,   xInt2     = 53;
    long     xLong1    = -4,   xLong2    = 54;
    float    xSingle1  = 5.0f, xSingle2  = 55.0f;
    double   xDouble1  = 6.0,  xDouble2  = 56.0;
    Decimal  xDecimal1 = 7m,   xDecimal2 = 57m;

// The following types are not CLS-compliant.
    sbyte    xSbyte1   = 101, xSbyte2  = 111;
    ushort   xUshort1  = 102, xUshort2 = 112;
    uint     xUint1    = 103, xUint2   = 113;
    ulong    xUlong1   = 104, xUlong2  = 114;

    Console.WriteLine("{0}Display the lesser of two values:{0}", nl);
    Console.WriteLine(str, "Byte   ", xByte1, xByte2, Math.Min(xByte1, xByte2));
    Console.WriteLine(str, "Int16  ", xShort1, xShort2, Math.Min(xShort1, xShort2));
    Console.WriteLine(str, "Int32  ", xInt1, xInt2, Math.Min(xInt1, xInt2));
    Console.WriteLine(str, "Int64  ", xLong1, xLong2, Math.Min(xLong1, xLong2));
    Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2));
    Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2));
    Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2));
//
    Console.WriteLine("{0}The following types are not CLS-compliant:{0}", nl);
    Console.WriteLine(str, "SByte  ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
    Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
    Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
    Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));
    }
}
/*
This example produces the following results:

Display the lesser of two values:

Byte   : The lesser of   1 and  51 is 1.
Int16  : The lesser of  -2 and  52 is -2.
Int32  : The lesser of  -3 and  53 is -3.
Int64  : The lesser of  -4 and  54 is -4.
Single : The lesser of   5 and  55 is 5.
Double : The lesser of   6 and  56 is 6.
Decimal: The lesser of   7 and  57 is 7.

The following types are not CLS-compliant:

SByte  : The lesser of 101 and 111 is 101.
UInt16 : The lesser of 102 and 112 is 102.
UInt32 : The lesser of 103 and 113 is 103.
UInt64 : The lesser of 104 and 114 is 104.
*/

[C++] 
// This example demonstrates Math.Min()
#using <mscorlib.dll>
using namespace System;

int main() 
{
    String* str = S"{0}: The lesser of {1,3} and {2,3} is {3}.";
    String* nl = Environment::NewLine;

    Byte     xByte1    = 1,    xByte2    = 51;    
    short    xShort1   = -2,   xShort2   = 52;
    int      xInt1     = -3,   xInt2     = 53;
    long     xLong1    = -4,   xLong2    = 54;
    float    xSingle1  = 5.0f, xSingle2  = 55.0f;
    double   xDouble1  = 6.0,  xDouble2  = 56.0;
    Decimal  xDecimal1 = 7,    xDecimal2 = 57;

// The following types are not CLS-compliant.
    SByte    xSbyte1   = 101, xSbyte2  = 111;
    UInt16   xUshort1  = 102, xUshort2 = 112;
    UInt32     xUint1    = 103, xUint2   = 113;
    UInt64    xUlong1   = 104, xUlong2  = 114;

    Console::WriteLine(S"{0}Display the lesser of two values:{0}", nl);
    Console::WriteLine(str, S"Byte   ", __box(xByte1), __box(xByte2), __box(Math::Min(xByte1, xByte2)));
    Console::WriteLine(str, S"Int16  ", __box(xShort1), __box(xShort2), __box(Math::Min(xShort1, xShort2)));
    Console::WriteLine(str, S"Int32  ", __box(xInt1), __box(xInt2), __box(Math::Min(xInt1, xInt2)));
    Console::WriteLine(str, S"Int64  ", __box(xLong1), __box(xLong2), __box(Math::Min(xLong1, xLong2)));
    Console::WriteLine(str, S"Single ", __box(xSingle1), __box(xSingle2), __box(Math::Min(xSingle1, xSingle2)));
    Console::WriteLine(str, S"Double ", __box(xDouble1), __box(xDouble2), __box(Math::Min(xDouble1, xDouble2)));
    Console::WriteLine(str, S"Decimal", __box(xDecimal1), __box(xDecimal2), __box(Math::Min(xDecimal1, xDecimal2)));
//
    Console::WriteLine(S"{0}The following types are not CLS-compliant:{0}", nl);
    Console::WriteLine(str, S"SByte  ", __box(xSbyte1), __box(xSbyte2), __box(Math::Min(xSbyte1, xSbyte2)));
    Console::WriteLine(str, S"UInt16 ", __box(xUshort1), __box(xUshort2), __box(Math::Min(xUshort1, xUshort2)));
    Console::WriteLine(str, S"UInt32 ", __box(xUint1), __box(xUint2), __box(Math::Min(xUint1, xUint2)));
    Console::WriteLine(str, S"UInt64 ", __box(xUlong1), __box(xUlong2), __box(Math::Min(xUlong1, xUlong2)));
}
/*
This example produces the following results:

Display the lesser of two values:

Byte   : The lesser of   1 and  51 is 1.
Int16  : The lesser of  -2 and  52 is -2.
Int32  : The lesser of  -3 and  53 is -3.
Int64  : The lesser of  -4 and  54 is -4.
Single : The lesser of   5 and  55 is 5.
Double : The lesser of   6 and  56 is 6.
Decimal: The lesser of   7 and  57 is 7.

The following types are not CLS-compliant:

SByte  : The lesser of 101 and 111 is 101.
UInt16 : The lesser of 102 and 112 is 102.
UInt32 : The lesser of 103 and 113 is 103.
UInt64 : The lesser of 104 and 114 is 104.
*/

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: 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, Common Language Infrastructure (CLI) Standard

参照

Math クラス | Math メンバ | System 名前空間 | Math.Min オーバーロードの一覧