[Tutor] How to correct decimal addition.

Keith Winston keithwins at gmail.com
Sat Jan 25 22:38:59 CET 2014


Also, just to be clear: I'd suggest floats because decimal requires
importing a module and using the non-built-in features thereof,
especially if you're going to do something like
decimal.getcontext().prec (even that doesn't set precision AFTER the
decimal point... only total precision). My point being that I don't
see the value of sending a beginner into that morass. I actually still
can't find how to force decimal to round to 3 places after the
decimal... (actually, I can't find a single reference to .prec except
in examples in the standard library doc of decimal
http://docs.python.org/3.3/library/decimal.html#decimal.getcontext)

And finally: when I said "watch out for rounding", I meant be prepared
for it. It is correct that rounding happens (otherwise the Snopes
Salami scam happens), and I can't imagine that at the level at which
the OP is working, any subtle control over rounding will be important
(i.e. ROUNDING_CEILING or any such thing).

Keith


More information about the Tutor mailing list