比较Delphi 7中的货币(在标签中存储为字符串)

时间:2015-07-26 02:32:34

标签: delphi delphi-7

Delphi 7 - 如何比较标签标题中的值(带小数的货币),值,即标签1 =' 12345.55'并标记2 =' 12345.56',并想知道哪一个值更大。

1 个答案:

答案 0 :(得分:2)

使用Currency函数将标签标题转换为SysUtils.StrToCurr()值,然后您可以使用常规算术运算符比较这些值。

Uses
  SysUtils;

var
  Val1, Val2: Currency;
begin
  Val1 := StrToCurr(Label1.Caption);
  Val2 := StrToCurr(Label2.Caption);
  if Val1 > Val2 then begin
    // label1 is bigger
  end
  else if Val1 < Val2 then begin
    // label2 is bigger
  end
  else begin
    // they are the same
  end;
end;