python format string thousand separator with spaces

wonzbak picture wonzbak · May 21, 2013 · Viewed 47.3k times · Source

For printing number with thousand separator, one can use the python format string :

'{:,}'.format(1234567890)

But how can I specify that I want a space for thousands separator?

Answer

Raz picture Raz · Sep 19, 2013

Here is bad but simple solution if you don't want to mess with locale:

'{:,}'.format(1234567890.001).replace(',', ' ')