Aliana Donovan
Aliana Donovan

Reputation: 71

Compare currency (stored as string in label) in Delphi 7

Delphi 7 - How to compare between values (currency with decimal) in my label caption, the values ie label 1 = '12345.55' and label 2 = '12345.56', and want to know which one is bigger value.

Upvotes: 0

Views: 423

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596206

Convert the label captions to Currency values using the SysUtils.StrToCurr() function, then you can compare those values using normal arithmetic operators.

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;

Upvotes: 2

Related Questions