[fpc-devel] Incorrect/Strange precision in FloatToStr and FloatToStrF

Graeme Geldenhuys graemeg.lists at gmail.com
Tue Jan 17 15:03:54 CET 2006


Hi,

[posted this again, as I didn't see it appear on the list]

Is this a bug?  The actual value of 234.502 is not greater than either
data types (extended or double), but the conversion to string result
using the Double is not what I expected.

Strangely enough 234.501 seem to work.  7.502 and 8.502 is another strange one!


procedure TForm1.Button4Click(Sender: TObject);
var
 Result: string;
 e: extended;
 r: double;
begin
 e := 234.502;
 Result := FloatToStrF(e, ffGeneral, 15, 0);
 Memo1.Lines.Add(Result);      { prints 234.502  }

 r := 234.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
 Memo1.Lines.Add(Result);  { prints 234.50200000000001 }

 r := 234.501;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
 Memo1.Lines.Add(Result);  { prints 234.501  Why does this work? }

 r := 7.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
 Memo1.Lines.Add(Result);  { prints 7.502 }

 r := 8.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
 Memo1.Lines.Add(Result);  { prints 8.502000000000001 }
end;


Regards,
 - Graeme -



More information about the fpc-devel mailing list