0

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.

7
  • Have a look here which boils down to setting Thread.CurrentThread.CurrentCulture and CurrentUICulture... Commented Dec 22, 2013 at 13:13
  • I have tried to apply a switch case in "InitializeCulture.cs",but still because Thread.CurrentThread.InstalledCulture = "en-US" Commented Dec 22, 2013 at 13:17
  • Show us your code by adding it to the question. Commented Dec 22, 2013 at 13:19
  • I have tried to apply a switch case in "InitializeCulture.cs",but still because CultureInfo.InstalledUICulture = "en-US",it doesn't work properly and number formatting doesn't happen property.I mean you can't save 2,00 as 2.00 according to "nl-NL". Commented Dec 22, 2013 at 13:27
  • I have shown the code in the question "<globalization uiCulture="CountryParam" culture="CountryParam" />",can we parameterize the globalization tag. Commented Dec 22, 2013 at 14:04

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Would be difficult to use String.Format every where as the application has integers and decimals which are use in calculations.Is there no way we can add parameter to the globalization tag and completely override the installed US culture.
@Shivam657 This is exactly what Thread.CurrentThread.CurrentCulture / UICulture is meant for ;) Just set it and you don't have to set it in all places... But of course you have to format your output, so if you output your decimal somewhere on the page, you have to use some formatting right? Usually this is done automatically. If you just output a decimal, most likely the ToString method will be invoked internally... and this one also uses the CurrentCulture set on the current thread as default...
Ya will try and do that.But is it possible to parameterize the globalization tag in web.config?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.