Skip to content

Commit 875990b

Browse files
committed
Added builtin approach for commas
1 parent 8d24dd5 commit 875990b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

formats.py

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def commas(N):
2222
return result
2323

2424

25+
def commas1(N):
26+
"""
27+
The more easiest way to format digits
28+
"""
29+
return '{:,}'.format(N)
30+
31+
2532
def money(N, numwidth=0, currency="$"):
2633
"""
2734
Format number N for display with commas, 2 decimal digits,
@@ -44,6 +51,13 @@ def selftest():
4451
for test in tests:
4552
print(commas(test))
4653

54+
print("-" * 80)
55+
56+
for test in tests:
57+
print(commas1(test))
58+
59+
print("-" * 80)
60+
4761
tests = 0, 1, -1, 1.23, 1., 1.2, 3.1341
4862
tests += 12, 123, 1234, 12345, 123456, 1234567
4963
tests += 2 ** 32, (2 ** 32 + .2342)

0 commit comments

Comments
 (0)