Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
i am developing an asp.net application site.the site is hosted in European server.

In european server the decimal seperator is ","
i have some double values in my application like 0.125
and some string to convert to double "0.125"
its working fine in local server,but showing comma instead of dot in live server.

i searched in google to change the decimal seperator and got more more ideas but not even single works for me.

my last attempt is following

static System.Globalization.NumberFormatInfo numberformat = null;
System.Globalization.CultureInfo info = System.Globalization.CultureInfo.InstalledUICulture;
numberformat = (System.Globalization.NumberFormatInfo)
info.NumberFormat.Clone();
numberformat.NumberDecimalSeparator = ".";
double duration=double.Parse("0.125",numberformat);


its not working.

Please help me to do it.
Posted
Updated 29-Dec-17 20:34pm

In addition to SA's answer, you can use InvariantCulture:

C#
double a = 0.125;
//decimal separator will always be '.'
string txt = a.ToString(System.Globalization.CultureInfo.InvariantCulture);
//back to a double
double a2 = double.Parse(txt, System.Globalization.CultureInfo.InvariantCulture);


I prefer this solution to store standard formated data into a file. You don't need to bother wich culture you used once you want to load them.
 
Share this answer
 
v2
Comments
kishore Rajendran 28-Apr-11 6:02am    
Works for me
thanks
Olivier Levrey 28-Apr-11 6:08am    
You are welcome.
You can accept the answer then or vote for it.
Thanks.
kishore Rajendran 28-Apr-11 6:20am    
is regional settings affect sql server?
am saving a value say 1.5 to DB
its saving as 1,5
any idea regarding this?


Please inform me
Olivier Levrey 28-Apr-11 6:33am    
I am sorry I have no knowledge about sql server. But if the value saved is 1,5 instead of 1.5 it means it is using regional settings. So you will have to use SA's answer.
Maybe you can setup your sql server to work with InvariantCulture?
kishore Rajendran 28-Apr-11 6:45am    
its ok np
Use format provider implemented by the type System.Globalization.CultureInfo.

For example:

C#
System.IFormatProvider cultureUS =
   new System.Globalization.CultureInfo("en-US");

System.Globalization.CultureInfo cultureFr =
   new System.Globalization.CultureInfo("fr-fr");

//...

double duration = double.Parse("0.125", cultureUS);
double length = double.Parse("25,1415", cultureFr);


—SA
 
Share this answer
 
v4
Comments
Abhinav S 28-Apr-11 1:38am    
Good answer. My 5.
Sergey Alexandrovich Kryukov 28-Apr-11 1:40am    
Thank you, Abhinav,
--SA
Ankit Rajput 28-Apr-11 1:46am    
Nice Answer. My 5.
Sergey Alexandrovich Kryukov 28-Apr-11 2:04am    
Thank you, Ankit.
--SA
kishore Rajendran 28-Apr-11 1:56am    
Not Working For me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900