python format string thousand separator with spaces

后端 未结 5 1510
悲哀的现实
悲哀的现实 2020-12-02 17:51

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

\'{:,}\'.format(1234567890)

But how can I specify that

5条回答
  •  天命终不由人
    2020-12-02 18:30

    This will set the locale environment to your default OS location:

    import locale
    locale.setlocale(locale.LC_ALL, '')
    

    Then you can use:

    "{0:n}".format(1234567890)
    

提交回复
热议问题