Display Numbers, currency, date & time etc with client's browser language.

I had a requirement to display numbers in reports with the current locale format. First client's suggestion was to use the regional settings of user who has logged in the server where our application was hosted. And I wrote the code and deployed the website. And changed my regional settings to French Canada. But still i was getting the numbers in en-US(USA) format. After doing some googling i found that it is because IIS is running under the "IUSR_machinename" account. So we should login with this credentials and change the regional settings. Or a work around for this is to go to registry and change the culture set for IUSR-SID in the path HKEY_USERS/IUSR-SID/Control Panel/International. But all these were not like a permanent and easy solution for this.
And easiest way is to use to culture from the clients browser. open IE. goto Tools->Options->Languages. Here you can find the language list. You can add or remove the languages of your choice. And the first one from the list will have highest priority. So using this language we can display numbers, date & time , currency etc in different formats. Below i am putting the code for this in C#.

/// Displays numbers, date time and currency according to the clients broswer language

private void FormattedValues()
string browserLanguage = string.Empty;

///Enables ASP.NET to read the HTTP values sent by a client during a Web request.
HttpRequest Request = HttpContext.Current.Request;
if (Request.UserLanguages != null)
browserLanguage = Request.UserLanguages[0];

if (!string.IsNullOrEmpty(browserLanguage))
int myNumber = 12342343;
int myCurrency = 1223423;
DateTime myDate = new DateTime();

if (browserLanguage.Length < 3)
browserLanguage = browserLanguage + "-" + browserLanguage.ToUpper();
///Create new culture with the language code generated from the browser
CultureInfo newCulture = CultureInfo.CreateSpecificCulture(browserLanguage);

/// Now set the culture and display the values
string formattedNumbumber = myNumber.ToString("N", newCulture);
string formattedCurrency = myCurrency.ToString("C", newCulture);
string formattedDatTime = myDate.ToString("d", newCulture);


This will help you when you want to implement Globalization in your web application.
Thanks a lot folks,


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: