Source From Here
Question
I am trying to print an integer in Python 2.6.1 with commas as thousands separators. For example, I want to show the number 1234567 as 1,234,567. How would I go about doing this? I have seen many examples on Google, but I am looking for the simplest practical way.
How-To
The Python standard library locale can help:
One simple example:
Sure, you don't need internationalization support, but it's clear, concise, and uses a built-in library. Another way is to use string format(Only works in Python 2.7 and higher.):
Question
I am trying to print an integer in Python 2.6.1 with commas as thousands separators. For example, I want to show the number 1234567 as 1,234,567. How would I go about doing this? I have seen many examples on Google, but I am looking for the simplest practical way.
How-To
The Python standard library locale can help:
One simple example:
Sure, you don't need internationalization support, but it's clear, concise, and uses a built-in library. Another way is to use string format(Only works in Python 2.7 and higher.):
沒有留言:
張貼留言