0
Hello, I’m having a problem with string to decimal conversion, as demonstrated by the following code:
string valor = "0,01";
CultureInfo _provider = new CultureInfo("pt-BR");
decimal valorTratado = Convert.ToDecimal(valor, _provider);
The variable Treaty value should be with the value 0.01 but it is with the value 1, someone knows why this happens?
For me it’s okay: https://dotnetfiddle.net/n68roP
– Maniero
always worked for me, but from a time started to happen this, is it some configuration of the visual studio? or other type of configuration? when I deploy in production is ok, but local happens this.
– Alexssandro Rocha Aquino
Replace the point with the comma before moving to the
ToDecimal
.– CypherPotato
I would just like to find out why this code has always worked and today it no longer works locally, I am with visual studio 2017 15.3.3
– Alexssandro Rocha Aquino
@Alexssandrorochaaquino Probably someone tampered with the computer’s location settings and switched the comma separator to a point (or any other).
– Jéf Bueno
The location settings were really wrong, it was in the Brazilian Portuguese language but the number settings as American English. by resetting settings to Portuguese back to normal.
– Alexssandro Rocha Aquino