Taimoor Pasha
Taimoor Pasha

Reputation: 310

Convert String into integer value

I need to make following string:

amount = "$163,852.06"

Like this:

16385206000

How can I do it, like I am following this method,:

money = "$163,852.06"
original_amount = ('').join(money[1:].split(','))
print(int(float(original_amount)))

But it is returning me:

163852

Upvotes: 0

Views: 52

Answers (2)

dawg
dawg

Reputation: 103694

>>> int(''.join(c for c in amount if c.isdigit()))*1000
16385206000

Upvotes: 1

Gian Dogwiler
Gian Dogwiler

Reputation: 1

It's because you're casting a floating point to an integer value, which rounds to the nearest full number. To achieve the value 16385206000, you could use int(float(original_amount) * 100000).

Upvotes: 0

Related Questions