~ubuntu-branches/ubuntu/lucid/python2.6/lucid

« back to all changes in this revision

Viewing changes to Doc/tutorial/stdlib2.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-03-11 13:30:19 UTC
  • mto: (10.1.13 sid)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20100311133019-sblbooa3uqrkoe70
Tags: upstream-2.6.5~rc2
ImportĀ upstreamĀ versionĀ 2.6.5~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
   >>> x = 1234567.8
62
62
   >>> locale.format("%d", x, grouping=True)
63
63
   '1,234,567'
64
 
   >>> locale.format("%s%.*f", (conv['currency_symbol'],
65
 
   ...               conv['frac_digits'], x), grouping=True)
 
64
   >>> locale.format_string("%s%.*f", (conv['currency_symbol'],
 
65
   ...                      conv['frac_digits'], x), grouping=True)
66
66
   '$1,234,567.80'
67
67
 
68
68
 
289
289
that stores only homogeneous data and stores it more compactly.  The following
290
290
example shows an array of numbers stored as two byte unsigned binary numbers
291
291
(typecode ``"H"``) rather than the usual 16 bytes per entry for regular lists of
292
 
python int objects::
 
292
Python int objects::
293
293
 
294
294
   >>> from array import array
295
295
   >>> a = array('H', [4000, 10, 700, 22222])
347
347
 
348
348
The :mod:`decimal` module offers a :class:`Decimal` datatype for decimal
349
349
floating point arithmetic.  Compared to the built-in :class:`float`
350
 
implementation of binary floating point, the new class is especially helpful for
351
 
financial applications and other uses which require exact decimal
352
 
representation, control over precision, control over rounding to meet legal or
353
 
regulatory requirements, tracking of significant decimal places, or for
354
 
applications where the user expects the results to match calculations done by
355
 
hand.
 
350
implementation of binary floating point, the class is especially helpful for
 
351
 
 
352
* financial applications and other uses which require exact decimal
 
353
  representation,
 
354
* control over precision,
 
355
* control over rounding to meet legal or regulatory requirements,
 
356
* tracking of significant decimal places, or
 
357
* applications where the user expects the results to match calculations done by
 
358
  hand.
356
359
 
357
360
For example, calculating a 5% tax on a 70 cent phone charge gives different
358
361
results in decimal floating point and binary floating point. The difference