LoveMyWife LoveMyWife - 1 year ago 189
C# Question

String to decimal conversion: dot separation instead of comma

I have a string read from a textbox. It contains a comma for decimal separation.

I have

set to
(comma) but when I convert the string to decimal
I obtain a dot separate value for decimal.


decimal a=Convert.ToDecimal("1,2345"); ----> decimal is 1.2345

I have tried also:

double a=Convert.ToDouble("1,2345");

but dot for decimal again

Answer Source

Thanks for all reply.

Because I have to write a decimal number in a xml file I have find out the problem. In this discussion I have learned that xml file standard use dot for decimal value and this is culture independent. So my solution is write dot decimal number in a xml file and convert the readed string from the same xml file mystring.Replace(".", ","); Thanks Agat for suggestion to research the problem in xml context and Ε Г И І И О because I didn't know visual studio doesn't respect the culture settings I have in my code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download