c# - decimal.Parse method -


i found weird bug in c# code,

so there next:

when i´m trying cast object{string} decimal :

item.valiafundo = row.isnull("pl_fundo") ? 0 : decimal.parse(row["pl_fundo"].tostring()); 

with value of row = "2488.1987", returns me 2488.1987 supposed, users returned value 24881987.

i fixed changing type of object database return object{decimal}, :

item.valiafundo = row.isnull("pl_fundo") ? 0 : (decimal)row["pl_fundo"]; 

that casts value user, , want understand why bug happens? cause it? have ideas?

p.s.: server , users regional settings same both cases.

but, seems data coming server decimal in type.

it bad practice go decimal --> string --> decimal.

as jon skeet pointed out (his answer disappeared) in cultures comma decimal point. when doing tostring() careful culture used.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -