round() function strange behaviour

Grant Edwards grante at visi.com
Mon Mar 11 14:12:06 EST 2002


In article <3c8cf137.2639944 at news>, brobbins333 at shaw.ca wrote:

> I understand and agree with what you  are saying. However, it is
> possible in some languages (VB, for example) to return a numerical
> result from a function with only two (or any other number) of decimal
> places.

If the language is using BCD representation then this is true.
If it's using binary FP, the this is not true. Some languages
have BCD math support.  Back in CP/M days, most language
implimentations (BASIC, FORTRAN, Pascal, whatever) supported
either BCD floating point or binary floating point.  The BCD
support was often called "financial mode" or something opaque
like that.

Python doesn't have BCD (at least not in the standard distro).

> Not a formatted string representation, but an actual numerical
> value that can be used in further calculations. This value is, of
> course, an approximation and has really been truncated rather than
> "rounded."

Either it's BCD and really does have "decimal places" or it's
binary FP, and it's exactly the same as what you get in Python.
I'll take your word for it that VB is using BCD.

> Anyway, we are arguing now over how many angels can dance on the head
> of a pin.

Not really.  Proper use of floating oint and functions like
round() require that the underlying representation is
understood.

-- 
Grant Edwards                   grante             Yow!  I'm rated PG-34!!
                                  at               
                               visi.com            



More information about the Python-list mailing list