Both, Borland Pascal 7 and Delphi 2007 have got the procedure STR which takes a number, a length and precision and converts it to a string like this:
str(9.234:5:1, s); // -> s = ' 9.2'
All is fine if the rounding is non-ambiguous, but if it isn't (0.5 -> up or down?) there is a problem: It seems to depend on the floating point data type in BP but is apparently consistent in Delphi 2007:
BP:
var
e: extended;
d: double;
begin
d := 2.15;
e := 2.15;
str(d:5:1, s); { -> s = ' 2.1' }
str(e:5:1, s); { -> s = ' 2.2' }
{ but: }
d := 2.25
e := 2.25
str(d:5:1, s); { -> s = ' 2.3' }
str(e:5:1, s); { -> s = ' 2.3' }
I was unable to find any rule on how doubles are being rounded, while apparently extendeds are always rounded up.
Delphi 2007 apparently always rounds up independent of the data type.
Does anybody know how the rounding is done in BP for double values?
I want to know because I am in the middle of porting some Borland Pascal code that uses doubles to Delphi 2007 and when I compare the outputs I get inconsistencies that result from rounding in the STR procedure. These do not really matter for the result but it makes it very difficult to spot important differences.