android decimal类型,Decimal.Compare(Decimal, Decimal) 方法 (System) | Microsoft Docs

比较两个指定的 Decimal 值。Compares two specified Decimal values.

public:

static int Compare(System::Decimal d1, System::Decimal d2);

public static int Compare (decimal d1, decimal d2);

static member Compare : decimal * decimal -> int

Public Shared Function Compare (d1 As Decimal, d2 As Decimal) As Integer

参数

要比较的第一个值。The first value to compare.

要比较的第二个值。The second value to compare.

返回

有符号数字,指示 d1 和 d2 的相对值。A signed number indicating the relative values of d1 and d2.

返回值Return value含义Meaning小于零Less than zerod1 小于 d2。d1 is less than d2.

零Zerod1 与 d2 相等。d1 and d2 are equal.

大于零Greater than zerod1 大于 d2。d1 is greater than d2.

示例

下面的示例比较了多个 Decimal 值。The following example compares several Decimal values. 请注意,第一个比较表明这两个值相等,尽管对该变量执行了减法运算 value2 。Note that the first comparison indicates that the two values are equal despite the subtraction operation performed on the value2 variable. 这是因为 Decimal 类型的精度为29位,而这两个值之间的差异只能检测到30位精度。This is because the Decimal type has 29 digits of precision, whereas a difference between these two values can be detected only with 30 digits of precision.

using System;

public enum Relationship

{ LessThan = -1, Equals = 0, GreaterThan = 1 }

public class Example

{

public static void Main()

{

decimal value1 = Decimal.MaxValue;

decimal value2 = value1 - .01m;

Console.WriteLine("{0} {2} {1}", value1, value2,

(Relationship) Decimal.Compare(value1, value2));

value2 = value1 / 12m - .1m;

value1 = value1 / 12m;

Console.WriteLine("{0} {2} {1}", value1, value2,

(Relationship) Decimal.Compare(value1, value2));

value1 = value1 - .2m;

value2 = value2 + .1m;

Console.WriteLine("{0} {2} {1}", value1, value2,

(Relationship) Decimal.Compare(value1, value2));

}

}

// The example displays the following output:

// 79228162514264337593543950335 Equals 79228162514264337593543950335

// 6602346876188694799461995861.2 GreaterThan 6602346876188694799461995861.1

// 6602346876188694799461995861.0 LessThan 6602346876188694799461995861.2

Public Enum Relationship As Integer

LessThan = -1

Equals = 0

GreaterThan = 1

End Enum

Module Example

Public Sub Main()

Dim value1 As Decimal = Decimal.MaxValue

Dim value2 As Decimal = value1 - .01d

Console.WriteLine("{0} {2} {1}", value1, value2,

CType(Decimal.Compare(value1, value2), Relationship))

value2 = value1 / 12d - .1d

value1 = value1 / 12d

Console.WriteLine("{0} {2} {1}", value1, value2,

CType(Decimal.Compare(value1, value2), Relationship))

value1 = value1 - .2d

value2 = value2 + .1d

Console.WriteLine("{0} {2} {1}", value1, value2,

CType(Decimal.Compare(value1, value2), Relationship))

End Sub

End Module

' The example displays the following output:

' 79228162514264337593543950335 Equals 79228162514264337593543950335

' 6602346876188694799461995861.2 GreaterThan 6602346876188694799461995861.1

' 6602346876188694799461995861.0 LessThan 6602346876188694799461995861.2

适用于

另请参阅

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值