sarath
sarath

Reputation: 19

How can I save numbers with comma delimiter stored as string as an integer in python

Result must include the delimiter.

Ex: a='1,000' of type string and the output must be: a=1,000 as an integer.

Upvotes: 1

Views: 378

Answers (1)

Ben Sh
Ben Sh

Reputation: 49

An integer won't include a comma. It's only for making the number readable that you add commas to it.

If you meant you want to parse the string into an integer, you should do the following:

num = int(a.replace(',', ''))

Afterwards if you want to present this integer with a comma again, you should just:

print "{:,}".format(num)

For back and fourth conversion in execution: Format and replace can help

Upvotes: 2

Related Questions