0

I have issue over using the CultureInfo call for getting the current culture from my machine. I have to use the number seperator as comma(,) instead of dot(.)

I went to regional settings->Additional Settings->Decimal symbol is set to comma(,).

I have my code as shown below

double number = 123.456;
string convertToString = Convert.ToString(number, CultureInfo.CurrentCulture);

I am getting my output same as 123.456, but my expected output is 123,456 (since i have set the decimal symbol as comma)

I tried explictly setting the number format as shown below

CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
culture.NumberFormat.NumberDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

I tried this in sample console application and i am getting the desired output(123,456), but if i try in WPF application, its not working.

Can I know where exactly i am doing wrong!

Chethan
  • 298
  • 1
  • 4
  • 17

2 Answers2

0

Try using CultureInfo.InstalledUICulture This will read de default OS setting.

  • CultureInfo.InstalledUICulture is always giving me "en-US", even tough in regional settings i have changed it to France ("fr-FR") – Chethan Sep 30 '14 at 09:49
0

Culture is actually a property of the executing thread. Can you explicitly set the culture of the current thread to one which you require and check?

//France as an example
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("fr-FR");
snippetkid
  • 282
  • 4
  • 16
  • this works for culture info "fr-FR", but the machine is set with "en-US" or any other culture, its not considering that culture info! I dont want to hard code any culture info, it should detect my machine culture info and give output accordingly! – Chethan Sep 30 '14 at 10:04