[fpc-devel] FormatFloat produces strange result based in different data types

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Mar 6 18:11:46 CET 2006


Hi

When pass 0.005 into the FormatFloat  and asking it to format with 2
decimal digits, using different data types (extended, double, single,
real), I get different result.  Also it is not consistent with Delphi.

I believe this is a bug, but not sure if it has already been address
in newer versions of FPC.  I am currently using 2.0.2

Free Pascal result:
e: $ 0.00                           <====  This is different
r: $ 0.01
d: $ 0.01
s: $ 0.00

Delphi result:
e: $ 0.01
r: $ 0.01
d: $ 0.01
s: $ 0.00



The program:

----------------------------------------------------------------
program project1;

{$mode objfpc}{$H+}

uses
 {$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
 {$ENDIF}{$ENDIF}
 Classes
 ,SysUtils;

var
 e: extended;
 r: real;
 d: double;
 s: single;
 result: string;
begin

 e := 0.005;
 r := 0.005;
 d := 0.005;
 s := 0.005;

 result := FormatFloat('$ #,##0.00', e);
 writeln('e: ' + result);
 result := FormatFloat('$ #,##0.00', r);
 writeln('r: ' + result);
 result := FormatFloat('$ #,##0.00', d);
 writeln('d: ' + result);
 result := FormatFloat('$ #,##0.00', s);
 writeln('s: ' + result);

end.
----------------------------------------------------------------


Regards,
 - Graeme -



More information about the fpc-devel mailing list