# Board index » delphi » Double and Currency

## Double and Currency

2003-11-07 03:22:06 AM
delphi80
hi everybody
I have a test on Delphi one of the Q. is
what is the different if Double variable := 34.27 and Currency variable
:= 34.27 then if
Double - currency the result := -3.1263880373e-15
for example:
procedure TForm1.Button1Click(Sender: TObject);
var
Discount :Double;
Sale :Currency;
begin
Sale:= 37.24;
Discount:=37.24;
Sale:= Sale-Discount;
end;
now sale= -3.1263880373e-15
but if I assign a other value the result = 0
Nathan XXXX@XXXXX.COM

## Re:Double and Currency

sory it must be 34.27 insted of 37.24
for example:
procedure TForm1.Button1Click(Sender: TObject);
var
Discount :Double;
Sale :Currency;
begin
Sale:= 34.27 ;
Discount:=34.27 ;
Sale:= Sale-Discount;
end;

## Re:Double and Currency

"Nathan" <XXXX@XXXXX.COM>writes
XXXX@XXXXX.COM...
##### Quote
what is the different if Double variable := 34.27 and Currency variable
:= 34.27 then if
Double - currency the result := -3.1263880373e-15
Floating-point types (Float, Double, Real, and Real48) are inexact; there
will always be a little "drift" in the exact value due to the internal
representation of the number. Fixed-point types (Currency) are actually
integer types with a built-in scale factor and so can represent values
exactly.
Cheers,
Ignacio
--
The strange part isn't so much that he had an accent. No accent was
detectable. It was just sounds and burbs and gurgles coming from him. He
was a like a chubby, old R2-D2.
- La Üter

## Re:Double and Currency

"Ignacio Vazquez" <ivazquezATorioncommunications.com>wrote
##### Quote
"Nathan" <XXXX@XXXXX.COM>wrote
>what is the different if Double variable := 34.27 and
>Currency variable := 34.27 then if
>Double - currency the result := -3.1263880373e-15
Floating-point types (Float, Double, Real, and Real48) are
inexact; there will always be a little "drift" in the exact value
...
Nathan and Ignacio,
Well not *always* <g>. Numbers that can be exactly
represented by reasonable size binary fractions like
0.5, 0.25, 0.375, and 34.25
can be exactly represented by those binary floating point
types single, double, extended, and Real48.
BTW:
When you do Double variable := 34.27, you get exactly
+34.27000 00000 00003 12638 80373 44440 81783
29467 77343 75
Best regards, JohnH