Board index » delphi » Help needed on comparing two float(currency) variables

Help needed on comparing two float(currency) variables

On Thu, 24 Jul 1997 14:17:28 +0100, James <ja...@jais.u-net.com>
wrote:

Quote
>I want to be able to compare 2 Currency variables to the nearest penny
>(2 decimal places) throughout my application.
>I can set     "CurrencyDecimals := 2"     in my application but this
>only is used in e.g. StrToFloatF using ffCurrency.
>Is there a built-in function or global setting which would simplify or
>remove the need for the following, not using string conversion ?

var
  a,b: Currency;
begin
  a:= 1.123;
  b:= 1.124;
  if abs(a-b)<0.005 {match to nearest penny} then
     Button1.Caption:= 'Success';
end;
 

Re:Help needed on comparing two float(currency) variables


I want to be able to compare 2 Currency variables to the nearest penny
(2 decimal places) throughout my application.
I can set     "CurrencyDecimals := 2"     in my application but this
only is used in e.g. StrToFloatF using ffCurrency.
Is there a built-in function or global setting which would simplify or
remove the need for the following, not using string conversion ?

var
  a,b: Currency;
begin
  a:= 1.123;
  a:= Round(a*100)/100;
  b:= 1.124;
  b:= Round(b*100)/100;
  if a = b then Button1.Caption:= 'Success';
end;

Many thanks if you can help me with this - I've been through all the
documentation I can find.....

Other Threads