Localization in .NET using IFormatProvider
May 26, 2008 Leave a comment
I was loading a string from a file and formatting it the current UI format .
For example , a number displayed as 12.34 ( in US English ) shall be displayed as 12,34 when the locale is of Sweden – in fact comma is the default decimal separator for most European countries.
Though the String::Format( ) provides an overloaded method with IFormatProvider, somehow the conversion never happened .
So as a workaround, I parsed the string to a double with the current UI culture format and then converted it to a string .
Maybe this is not the best way, but as it worked for me , I am posting a sample below, so it can be helpful for others.
String^ myString= “12.34”;
double tempD = double::Parse(myString,Thread::CurrentThread->CurrentUICulture->NumberFormat );