There are several ways to format numbers in Python:
format() method:main.py63 chars3 lines
Output:
main.py26 chars2 lines
main.py55 chars3 linesOutput:
main.py26 chars2 lines
round() method:main.py89 chars4 lines
Output:
main.py26 chars2 lines
locale module:main.py173 chars7 lines
Output:
main.py28 chars2 lines
Note that the locale module formats the number according to the current locale settings of your operating system.
gistlibby LogSnag