0
I did a little research before I asked, can you tell me why it doesn’t show 2,500 on the way out, but 2.5
salario=float(input("Digite seu salario"))
print(salario)
0
I did a little research before I asked, can you tell me why it doesn’t show 2,500 on the way out, but 2.5
salario=float(input("Digite seu salario"))
print(salario)
2
Because 2.5 equals 2,500, just take the test:
print(2.5 == 2.500)
Will return True
The point is used as separate from the "floating point", That is why it is called "floating point", then the right zeros are deleted, the same occurs with calculators.
Now if your goal is to use ,
as separator and points as thousand separators the story is another, would have to use replace
, for example:
x = '2.500,01'
x = x.replace('.', '').replace(',', '.')
x = float(x)
print(x)
If you have R$
in the string passed use:
x = 'R$ 2.500,01'
x = x.replace('R$', '') # remove o R$
x = x.strip() # remove espaços em branco
x = x.replace('.', '') # remove os pontos
x = x.replace(',', '.') # troca virgula do decimal por ponto
x = float(x)
print(x)
Browser other questions tagged python float conversion
You are not signed in. Login or sign up in order to post.
In my case it was for the amount R $ 2.500,00.
– André Silva
@Andrésilva then uses the second example I posted, understand one thing, number is number, string is string, that for the computer is not a number "2,500.00" is a string, with the replace as shown you convert to number.
– Guilherme Nascimento
Got it man thanks a lot for the tips, I’ll try!
– André Silva