Insert comma in number?

E

eli m

I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number.
For example: instead of 1000 it would say 1,000
 
I

ian douglas

I have a python program that accepts input and calculates the factorial of that number, and i want to know if i can make it so commas get inserted in the number.
For example: instead of 1000 it would say 1,000


pip install humanize


import humanize
my_integer = 12345678
commafied_integer = humanize.intcomma(my_integer)
print commafied_integer


output:
12,345,678
 
P

Peter Otten

eli said:
I have a python program that accepts input and calculates the factorial of
that number, and i want to know if i can make it so commas get inserted in
the number. For example: instead of 1000 it would say 1,000

Last not least there's the option to employ locale-aware formatting:
'12,345'

In German usage of "." and "," is reversed, so:
'12.345'
 
P

Paul Volkov

2013/3/7 Peter Otten said:
Last not least there's the option to employ locale-aware formatting:

'12,345'

In German usage of "." and "," is reversed, so:

'12.345'

Does this locale-aware example only work on UNIX?
 
P

Peter Otten

Paul said:
Does this locale-aware example only work on UNIX?

If you have Windows in mind: I don't know what it takes to get multiple
locales on a Windows system, but for the default locale that you can specify
with

locale.setlocale(locale.LC_ALL, "")

it should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top