Overriding certain culture aspects when using ASP.NET Globalization.
Tuesday, July 15, 2008 11:12ASP.NET Globalization greatly eases the development of websites in multiple languages by using the language settings from the visitors web browser.
This works great, but there are situations that you might not want to use globalization for all possible settings. For example, if you have an auction site and all currency values are stored in a database, you might not want to have the globalization format your money variables to another currency. This will happen if you use format strings like {0:C} for your string formatting.
If you want to ‘globalize’ your pages and want to format numbers in the way the clients culture expects them, but do not want to change the currency symbol, you can override the InitializeCulture method on your pages. This example will always format currency in the correct currency format, but it will always show the Euro sign next to it;
protected override void InitializeCulture()
{
base.InitializeCulture();
Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture.Clone() as CultureInfo; Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol = "€ ";
}
That will do the trick.
One Response to “Overriding certain culture aspects when using ASP.NET Globalization.”
Leave a Reply
You must be logged in to post a comment.

mırc says:
July 24th, 2008 at 7:09 AM
thanks