Question

I have an object with a number property (double) and has no specific culture set. This property is derived from a database when the user logs into the website. The culture formatting in the database is en-GB.

When the property is called and returns to a label on the website, the number is displayed in their local culture format.

My question is, does the object property retain a en-GB culture format and the browser just displays it in local culture format, OR, does the object actually store that property in the users local culture formatting?

I have a lot of trouble working with number formats for different cultures (multi-lingual site), and I wondered how I should be handling these sort of properties because I have to make calculations based on these figures and other figure input by the user on the website, display to the user in their local format, but always submit data back to our database in our local format (en-GB).

Was it helpful?

Solution 2

The number value itself is just a number. The formatting of the number depends on how you present the text representation of that number to the user.

Parsing the number value from user input would again depend on how you allow the user to enter the value. As long as you know the culture of the input string, you can parse it back to an actual number, which is culture independant.

OTHER TIPS

The property does not store the cultue. The formatting is based on Thread.CurrentUICulture, which is the culture on the server side.

Assuming you are developing a ASP.NET website:

CultureInfo culture = new CultureInfo(Request.UserLanguages[0]);
return double.Parse("1.5", culture.NumberFormat);

This converts the double using the culture settings provided by the client.

For more information: http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx

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