I tried this code using the decimal standard library module:
>>> from decimal import *
>>> getcontext().prec = 6
>>> Decimal(22)/Decimal(7)
Decimal('3.14286')
It appears to have rounded the value to the nearest representable one.
How can I make it truncate instead, to give a result of 3.14285?
Just like you specify precision using the Decimal context you can also specify rounding rules.
the result will be
http://docs.python.org/release/3.1.5/library/decimal.html#decimal.Context