Question

I am working on an application in which user has to enter the country he/she belongs to.

We want this to implement culture specific number formatting every time a user enter his/her country. Can we pass the country parameter to the globalization tag in web.config to make the application behave in accordance to the user's selected country?

<globalization uiCulture="CountryParam"  culture="CountryParam" />

Any help is deeply appreciated.

Was it helpful?

Solution

IN Asp.Net and/or MVC you just have to set Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture to the culture of the user

If you do so, all formatting should be done based on this culture per default.

Otherwise you would have to run string.Format with the specific culture provided by you in all places you do string formatting, using this overload...

As you can see in the documentation of string.Format, without defining a specific culture, it will use Thread.CurrentThread.CurrentCulture

Taken from here

Generally, objects in the argument list are converted to their string representations by using the conventions of the current culture, which is returned by the CultureInfo.CurrentCulture property. You can control this behavior by calling the Format(IFormatProvider, String, Object[]) overload. This overload's provider parameter is an IFormatProvider implementation that supplies custom and culture-specific formatting information that is used to moderate the formatting process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top