fork(2) download
  1. def special_format(n):
  2. s, *d = str(n).partition(".")
  3. r = ",".join([s[x-2:x] for x in range(-3, -len(s), -2)][::-1] + [s[-3:]])
  4. return "".join([r] + d)
  5.  
  6. print(special_format(1))
  7. print(special_format(12))
  8. print(special_format(123))
  9. print(special_format(1234))
  10. print(special_format(12345))
  11. print(special_format(123456))
  12. print(special_format(12345678901234567890))
  13. print(special_format(1.0))
  14. print(special_format(12.34))
  15. print(special_format(1234567890.1234567890))
  16.  
Success #stdin #stdout 0.02s 9944KB
stdin
Standard input is empty
stdout
1
12
123
1,234
12,345
1,23,456
1,23,45,67,89,01,23,45,67,890
1.0
12.34
1,23,45,67,890.1234567