I have got the value from database 350,000,000.00 now I need to convert it to 350000000. Please provide a solution on this using Python 3.6+ version
Thanks
I have got the value from database 350,000,000.00 now I need to convert it to 350000000. Please provide a solution on this using Python 3.6+ version
Thanks
Let the input be in a variable, say
a="350,000,000.00"
Since, the digits are comma ,
separated, that needs to be removed.
a.replace(",","")
>>> 350000000.00
The resultant string
is a float
. When we directly convert the string to integer, it will result in an error.
int(a.replace(",",""))
>>>Traceback (most recent call last):
File "python", line 2, in <module>
ValueError: invalid literal for int() with base 10: '350000000.00'
So, convert the number to float
and then to int
.
int(float(a.replace(",","")))
>>>350000000
Store the value in a variable and then parse it with int(variable_name)
eg. If you store the value in variable a, just write int(float(a))
def convert(a):
r = 0
s = a.split(".")[0]
for c in s.split(","):
r = r * 1000 + int(c)
return r
s = convert("350,000,000.00")