 |
|
 |
It's simple and does exactly what I needed
|
|
|
|
 |
|
 |
this article was helped for my work, thanks a lot.
|
|
|
|
 |
|
 |
Double.Parse(stringvar, System.Globalization.CultureInfo.InvariantCulture.NumberFormat)
Richard "String Breaker"
|
|
|
|
 |
|
 |
Thanks for the tip...really useful !
|
|
|
|
 |
|
 |
i want change current windows regional in my system
in fact i want change digits shape into my country digits shape (Farsi)
windows default regional is English(United states) and i want change it in my application to Farsi
in english regional digits are 1234567890
but in farsi regional digits are ۱۲۳۴۵۶۷۸۹۰
i just want do it
please help me
|
|
|
|
 |
|
 |
Hi,
Is there a way to change this locale settings of the whole program at startup/compile time?
My locale has "," insted of "." as the floating point separator. I'm currently parsing dot-separated floats (X.X) with my own instance of NumberFormatInfo. However when I print those numbers (after a successful parse) it uses my locale and thus I get the ugly format of X,X. I can of course change this formatting as well, but...
Maybe there's a way to change the whole program's locale so I wouldn't need to neither change the separator while parsing nor while printing?
I'd just like to have a program which would think it's in England or something like that.
[ QmQ ]
|
|
|
|
 |
|
 |
Sure, you can change the CurrentCulture, or CurrentUICulture globally for the application:
Thread.CurrentThread.CurrentCulture = new CultureInfo( "en-US", false );
that way you force the application to use specific culture settings for number formatting, date formatting etc.
MC
|
|
|
|
 |
|
 |
Great Thanks a lot! This will make things a lot easier.
Pozdrawiam (Best regards ),
[ QmQ ]
|
|
|
|
 |
|
 |
Why not place the code from the constructor in a static constructor, that way it will be done when needed the first time, and won't be done again for every instance, the ni field is static anyway.
|
|
|
|
 |
|
 |
I get this error when I execute the code of the article in my project:
"The number separator information specified in the NumberFormatInfo is
ambiguous for parsing"
How can I solve it??
Thanks in advance.
|
|
|
|
 |
|
 |
HI, If you want to support booth . and , for the users this may be a solution:
public static double StringToDouble(string stringNum) {
string decimalCharacter
System.Globalization.CultureInfo.InstalledUICulture.NumberFormat.NumberDecimalSeparator;
stringNum.Replace(".", decimalCharacter);
stringNum.Replace(",", decimalCharacter);
try {
return double.Parse(stringNum);
}
catch (Exception ex){
throw ex;
}
}
/M
|
|
|
|
 |
|
 |
not quite...
You should write:
stringNum = stringNum.Replace(".", decimalCharacter);
stringNum = stringNum.Replace(",", decimalCharacter);
sincerly
Michal Rorat
Poland
|
|
|
|
 |
|
 |
not quite...
You should write:
string decimalCharacter = System.Globalization.CultureInfo.InstalledUICulture.NumberFormat.NumberDecimalSeparator;
stringNum = stringNum.Replace(".", decimalCharacter);
stringNum = stringNum.Replace(",", decimalCharacter);
sincerly
Michal Rorat
Poland
|
|
|
|
 |
|
 |
Yes of course.. excuse my typo.. (commented a year later)
However, nowdays i create my own System.Globalization.NumberFormatInfo object when parsing text to a numer. In that way i get full control of how to parse the text.
And... I have created my own litte static funtion for this... you may borrow it if you find i usefull.
public static double ToDouble(string stringNum, params string[] decimalSeparators) {
System.Globalization.NumberFormatInfo formatInfo = new System.Globalization.NumberFormatInfo();
if (decimalSeparators.Length == 0) {
// decimal separator from current culture.
formatInfo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
}
else {
// use all of the custom separators.
formatInfo.NumberDecimalSeparator = decimalSeparators[0];
for (int i=0; i0) {
stringNum = stringNum.Replace(decimalSeparators[i], decimalSeparators[0]);
}
}
}
try {
return double.Parse(stringNum, formatInfo);
}
catch (FormatException){
return double.NaN;
}
}
and to use this you can write:
double niceDouble = ToDouble(stringToConvert, ".", ",", ";", ":");
/Mattias
|
|
|
|
 |
 | Hint  |  | Anonymous | 2:19 21 Apr '04 |
|
 |
in germany the grouping character is "." so if you change the decimal separator, don't forget to change the grouping separator as well, for you might get an exception.
ciao, andré
|
|
|
|
 |
|
 |
Nice reference Mr "Tepes"
|
|
|
|
 |
|
 |
Hi,
Why not using:
someNumber = double.Parse(myNumber.Replace(",","."));
John
|
|
|
|
 |
|
 |
The concept is the important thing here, not the implementation. There is a lot more to internationalization than just replacing a comma with a decimal point. What if the software in question was already running in a European locale, then you code might cause it to fail.
Being able to specify locales during conversion is nice. I wish CRT had that ability.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
 |
|
 |
Yes you're right
|
|
|
|
 |