Decimal.Compare 메서드
지정된 두 Decimal 값을 비교합니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Shared Function Compare ( _
d1 As Decimal, _
d2 As Decimal _
) As Integer
‘사용 방법
Dim d1 As Decimal
Dim d2 As Decimal
Dim returnValue As Integer
returnValue = Decimal.Compare(d1, d2)
public static int Compare (
decimal d1,
decimal d2
)
public:
static int Compare (
Decimal d1,
Decimal d2
)
public static int Compare (
Decimal d1,
Decimal d2
)
public static function Compare (
d1 : decimal,
d2 : decimal
) : int
매개 변수
- d1
Decimal입니다.
- d2
Decimal입니다.
반환 값
d1과 d2의 상대 값을 나타내는 부호 있는 숫자를 반환합니다.
반환 값 |
의미 |
---|---|
0보다 작음 |
d1이 d2보다 작습니다. |
0 |
d1과 d2가 같습니다. |
0보다 큼 |
d1이 d2보다 큽니다. |
예제
다음 코드 예제에서는 Compare 메서드를 사용하여 몇 개의 Decimal 값과 참조 Decimal 값을 비교합니다.
' Example of the Decimal.Compare and static Decimal.Equals methods.
Imports System
Imports Microsoft.VisualBasic
Module DecCompareEqualsDemo
Const dataFmt As String = "{0,-45}{1}"
' Compare Decimal parameters, and display them with the results.
Sub CompareDecimals( Left as Decimal, Right as Decimal, _
RightText as String )
Console.WriteLine( )
Console.WriteLine( dataFmt, "Right: " & RightText, Right )
Console.WriteLine( dataFmt, "Decimal.Equals( Left, Right )", _
Decimal.Equals( Left, Right ) )
Console.WriteLine( dataFmt, _
"Decimal.Compare( Left, Right )", _
Decimal.Compare( Left, Right ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the Decimal.Equals( Decimal, " & _
"Decimal ) and " & vbCrLf & "Decimal.Compare( " & _
"Decimal, Decimal ) methods generates the " & vbCrLf & _
"following output. It creates several different " & _
"Decimal " & vbCrLf & "values and compares them " & _
"with the following reference value." & vbCrLf )
' Create a reference Decimal value.
Dim Left as New Decimal( 123.456 )
Console.WriteLine( dataFmt, "Left: Decimal( 123.456 )", Left )
' Create Decimal values to compare with the reference.
CompareDecimals( Left, New Decimal( 1.2345600E+2 ), _
"Decimal( 1.2345600E+2 )" )
CompareDecimals( Left, 123.4561D, "123.4561D" )
CompareDecimals( Left, 123.4559D, "123.4559D" )
CompareDecimals( Left, 123.456000D, "123.456000D" )
CompareDecimals( Left, _
New Decimal( 123456000, 0, 0, false, 6 ), _
"Decimal( 123456000, 0, 0, false, 6 )" )
End Sub
End Module
' This example of the Decimal.Equals( Decimal, Decimal ) and
' Decimal.Compare( Decimal, Decimal ) methods generates the
' following output. It creates several different Decimal
' values and compares them with the following reference value.
'
' Left: Decimal( 123.456 ) 123.456
'
' Right: Decimal( 1.2345600E+2 ) 123.456
' Decimal.Equals( Left, Right ) True
' Decimal.Compare( Left, Right ) 0
'
' Right: 123.4561D 123.4561
' Decimal.Equals( Left, Right ) False
' Decimal.Compare( Left, Right ) -1
'
' Right: 123.4559D 123.4559
' Decimal.Equals( Left, Right ) False
' Decimal.Compare( Left, Right ) 1
'
' Right: 123.456000D 123.456
' Decimal.Equals( Left, Right ) True
' Decimal.Compare( Left, Right ) 0
'
' Right: Decimal( 123456000, 0, 0, false, 6 ) 123.456000
' Decimal.Equals( Left, Right ) True
' Decimal.Compare( Left, Right ) 0
// Example of the decimal.Compare and static decimal.Equals methods.
using System;
class DecCompareEqualsDemo
{
const string dataFmt = "{0,-45}{1}";
// Compare decimal parameters, and display them with the results.
public static void CompareDecimals( decimal Left, decimal Right,
string RightText )
{
Console.WriteLine( );
Console.WriteLine( dataFmt, "Right: "+RightText, Right );
Console.WriteLine( dataFmt, "decimal.Equals( Left, Right )",
Decimal.Equals( Left, Right ) );
Console.WriteLine( dataFmt, "decimal.Compare( Left, Right )",
Decimal.Compare( Left, Right ) );
}
public static void Main( )
{
Console.WriteLine( "This example of the " +
"decimal.Equals( decimal, decimal ) and \n" +
"decimal.Compare( decimal, decimal ) methods " +
"generates the \nfollowing output. It creates several " +
"different decimal \nvalues and compares them with " +
"the following reference value.\n" );
// Create a reference decimal value.
decimal Left = new decimal( 123.456 );
Console.WriteLine( dataFmt, "Left: decimal( 123.456 )",
Left );
// Create decimal values to compare with the reference.
CompareDecimals( Left, new decimal( 1.2345600E+2 ),
"decimal( 1.2345600E+2 )" );
CompareDecimals( Left, 123.4561M, "123.4561M" );
CompareDecimals( Left, 123.4559M, "123.4559M" );
CompareDecimals( Left, 123.456000M, "123.456000M" );
CompareDecimals( Left,
new decimal( 123456000, 0, 0, false, 6 ),
"decimal( 123456000, 0, 0, false, 6 )" );
}
}
/*
This example of the decimal.Equals( decimal, decimal ) and
decimal.Compare( decimal, decimal ) methods generates the
following output. It creates several different decimal
values and compares them with the following reference value.
Left: decimal( 123.456 ) 123.456
Right: decimal( 1.2345600E+2 ) 123.456
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
Right: 123.4561M 123.4561
decimal.Equals( Left, Right ) False
decimal.Compare( Left, Right ) -1
Right: 123.4559M 123.4559
decimal.Equals( Left, Right ) False
decimal.Compare( Left, Right ) 1
Right: 123.456000M 123.456000
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
Right: decimal( 123456000, 0, 0, false, 6 ) 123.456000
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
*/
// Example of the Decimal::Compare and static Decimal::Equals methods.
using namespace System;
const __wchar_t * protoFmt = L"{0,-45}{1}";
// Compare Decimal parameters, and display them with the results.
void CompareDecimals( Decimal Left, Decimal Right, String^ RightText )
{
String^ dataFmt = gcnew String( protoFmt );
Console::WriteLine();
Console::WriteLine( dataFmt, String::Concat( "Right: ", RightText ), Right );
Console::WriteLine( dataFmt, "Decimal::Equals( Left, Right )", Decimal::Equals( Left, Right ) );
Console::WriteLine( dataFmt, "Decimal::Compare( Left, Right )", Decimal::Compare( Left, Right ) );
}
int main()
{
Console::WriteLine( "This example of the Decimal::Equals( Decimal, Decimal "
") and \nDecimal::Compare( Decimal, Decimal ) "
"methods generates the \nfollowing output. It creates "
"several different Decimal \nvalues and compares them "
"with the following reference value.\n" );
// Create a reference Decimal value.
Decimal Left = Decimal(123.456);
Console::WriteLine( gcnew String( protoFmt ), "Left: Decimal( 123.456 )", Left );
// Create Decimal values to compare with the reference.
CompareDecimals( Left, Decimal(1.2345600E+2), "Decimal( 1.2345600E+2 )" );
CompareDecimals( Left, Decimal::Parse( "123.4561" ), "Decimal::Parse( \"123.4561\" )" );
CompareDecimals( Left, Decimal::Parse( "123.4559" ), "Decimal::Parse( \"123.4559\" )" );
CompareDecimals( Left, Decimal::Parse( "123.456000" ), "Decimal::Parse( \"123.456000\" )" );
CompareDecimals( Left, Decimal(123456000,0,0,false,6), "Decimal( 123456000, 0, 0, false, 6 )" );
}
/*
This example of the Decimal::Equals( Decimal, Decimal ) and
Decimal::Compare( Decimal, Decimal ) methods generates the
following output. It creates several different Decimal
values and compares them with the following reference value.
Left: Decimal( 123.456 ) 123.456
Right: Decimal( 1.2345600E+2 ) 123.456
Decimal::Equals( Left, Right ) True
Decimal::Compare( Left, Right ) 0
Right: Decimal::Parse( "123.4561" ) 123.4561
Decimal::Equals( Left, Right ) False
Decimal::Compare( Left, Right ) -1
Right: Decimal::Parse( "123.4559" ) 123.4559
Decimal::Equals( Left, Right ) False
Decimal::Compare( Left, Right ) 1
Right: Decimal::Parse( "123.456000" ) 123.456000
Decimal::Equals( Left, Right ) True
Decimal::Compare( Left, Right ) 0
Right: Decimal( 123456000, 0, 0, false, 6 ) 123.456000
Decimal::Equals( Left, Right ) True
Decimal::Compare( Left, Right ) 0
*/
// Example of the decimal.Compare and static decimal.Equals methods.
import System.* ;
class DecCompareEqualsDemo
{
private static String dataFmt = "{0,-45}{1}";
// Compare decimal parameters, and display them with the results.
public static void CompareDecimals(System.Decimal left,
System.Decimal right, String rightText)
{
Console.WriteLine();
Console.WriteLine(dataFmt, "Right: " + rightText,right);
Console.WriteLine(dataFmt, "decimal.Equals( Left, Right )",
System.Convert.ToString(Decimal.Equals(left,right)));
Console.WriteLine(dataFmt, "decimal.Compare( Left, Right )",
System.Convert.ToString(Decimal.Compare(left,right)));
} //CompareDecimals
public static void main(String[] args)
{
Console.WriteLine(("This example of the "
+ "decimal.Equals( decimal, decimal ) and \n"
+ "decimal.Compare( decimal, decimal ) methods "
+ "generates the \nfollowing output. It creates several "
+ "different decimal \nvalues and compares them with "
+ "the following reference value.\n"));
// Create a reference decimal value.
System.Decimal left = new System.Decimal(123.456);
Console.WriteLine(dataFmt, "Left: decimal( 123.456 )",left);
// Create decimal values to compare with the reference.
CompareDecimals(left,
new System.Decimal(123.456), "decimal( 1.2345600E+2 )");
CompareDecimals(left, System.Convert.ToDecimal(123.4561), "123.4561");
CompareDecimals(left, System.Convert.ToDecimal(123.4559), "123.4559");
CompareDecimals(left,System.Convert.ToDecimal(123.456000),"123.456000");
CompareDecimals(left, new System.Decimal(123456000, 0, 0, false,
System.Convert.ToByte(6)), "decimal( 123456000, 0, 0, false, 6 )");
} //main
} //DecCompareEqualsDemo
/*
This example of the decimal.Equals( decimal, decimal ) and
decimal.Compare( decimal, decimal ) methods generates the
following output. It creates several different decimal
values and compares them with the following reference value.
Left: decimal( 123.456 ) 123.456
Right: decimal( 1.2345600E+2 ) 123.456
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
Right: 123.4561 123.4561
decimal.Equals( Left, Right ) False
decimal.Compare( Left, Right ) -1
Right: 123.4559 123.4559
decimal.Equals( Left, Right ) False
decimal.Compare( Left, Right ) 1
Right: 123.456000 123.456
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
Right: decimal( 123456000, 0, 0, false, 6 ) 123.456000
decimal.Equals( Left, Right ) True
decimal.Compare( Left, Right ) 0
*/
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원