Format value in pyhton [closed]

1

I have a crawler where I get values in this format: "$ 450,000.00."

But I need to convert these values to float and save in the database to make queries of this type: Get the values that are between 40,000.00 and 100,000.00.

    
asked by anonymous 02.01.2017 / 17:16

1 answer

1

You can do this:

valorRaw = 'R$ 450,000.00'
valor = float(valor.split('$')[1].replace(',', '')) # 450000.0

Assuming you're sure values always come in that format

OU:

valorRaw = 'R$ 450,000.00'
valor = float(valor[2:].replace(',', '')) # 450000.0

[2:] means that we want everything from index 2 ("$") and then we remove the comma if there is

    
02.01.2017 / 17:20