Both Borland Pascal 7 and Delphi 2007 received the STR procedure, which takes a number, length, and precision, and converts it to a string as follows:
str(9.234:5:1, s); // -> s = ' 9.2'
Everything is fine if rounding is not ambiguous, but if it is not (0.5 β up or down?), A problem arises: it seems to depend on the data type of the floating point in BP, but apparently 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 not able to find any rule about how rounded doubles, while obviously expanded are always rounded.
Delphi 2007 seems to always be rounded regardless of the data type.
Does anyone know how rounding is done in BP for double values?
I want to know, because I'm in the middle of migrating some Borland Pascal code that uses duplicates for Delphi 2007, and when I compare the outputs, I get inconsistencies resulting from rounding in the STR procedure. This is not particularly significant for the result, but it makes it difficult to identify important differences.
source share