Jump to content
KWK

Bug in Automatic Rounding of Reals in Write statements ?

Recommended Posts

Generally in Pascal, writing a real, specifying field length and number of decimals, rounds to that number of decimals.  Thus x:=1.27; writeln(x:3:1) produces "1.3"

However, in DelphiXE2 x:=0.9; writeln(x:3:0) produces "  0"  while x:=1.9; writeln(x:3:0) produces "  2". 

(This also happens if you just do writeln(0.9:3:0) and writeln(1.9:3:0)

For some reason, reals with an absolute value less than 1 are not rounded, but reals with an absolute value >1 are rounded.  My example has just one decimal, but I discovered this while trying to print probabilities where writing a calculated  value x:=0.000647; writeln(x:8:3) produced 0.000 rather than 0.001 which is correct.

This appears to me to be a bug,.  Is this true in more recent versions of RAD Studio?

Thank you.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×