···77--------
88Almost all platforms map Python floats to [IEEE 754](/formats/fp/)
99double precision.
1010-1111- f = 0.1
1010+ f = 0.1
12111312Decimal Types
1413-------------
1514Python has an [arbitrary-precision](/formats/exact/) decimal type named <code>Decimal</code> in the <code>decimal</code> module, which
1615also allows to choose the [rounding mode](/errors/rounding/).
1717- a = Decimal('0.1')
1818- b = Decimal('0.2')
1919- c = a + b # returns a Decimal representing exactly 0.3
2020-1616+ a = Decimal('0.1')
1717+ b = Decimal('0.2')
1818+ c = a + b # returns a Decimal representing exactly 0.3
21192220How to Round
2321------------
2422To get a string:
2525- "%.2f" % 1.2399 # returns "1.24"
2323+ "%.2f" % 1.2399 # returns "1.24"
2624 "%.3f" % 1.2399 # returns "1.240"
2725 "%.2f" % 1.2 # returns "1.20"
2826To print to standard output:
2927 print "%.2f" % 1.2399 # just use print and string formatting
3030-If you need a specific [rounding mode](/errors/rounding/) and other parameters can be defined in a Context object:
3131- getcontext().prec = 7
2828+Specific [rounding modes](/errors/rounding/) and other parameters can be defined in a Context object:
2929+ getcontext().prec = 7
32303331Resources
3432---------