How to truncate/round-off decimal numbers?

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Jun 21 04:57:57 EDT 2006


In article <1150875897.866447.312150 at g10g2000cwb.googlegroups.com>,
"per9000" <per9000 at gmail.com> writes:
|> 
|> just a thought: if you *always* work with "floats" with two decimals,
|> you are in fact working with integers, but you represent them as a
|> floats - confusing for the internal representation.

No, you aren't - you are working with fixed-point, which is something
that is neither integers nor floating-point, but is somewhere in
between.  I am (just) old enough to remember when it was used for
numeric work, and to have used it for that myself, but not old enough
to have done any numeric work using fixed-point hardware.

|> So why not work with int(float * 100) instead? This way you only have
|> to take care of roundoffs etc when dividing.

And multiplying, and calling most mathematical functions.


Regards,
Nick Maclaren.



More information about the Python-list mailing list