Localized Currencies and Decimals using MicrosoftAjax.js
09 Jul 2010
Visual Studio Solution Explorer
Simply add a reference to the script file within the <head> tag of your html content.
In order to make use of the MicrosoftAjax library it must first be configured by setting the desired UI culture, otherwise it defaults to "en-US". It is most likely that you will want the UI culture set to the user's browser culture. To configure your application to read the current culture from the user's selected browser culture add a <Globalization /> tag to the web.config.
Once the MicrosoftAjax library has been included and configured correctly there are two main methods that are useful when dealing with localized currencies and decimals. The first method is Number.parseLocal(string). This method parses a decimal or currency string into a number value, taking into consideration the selected culture's defined number formatting properties.
So, for example, if the current culture was set to "fr-FR" the above code would output "2.75". Thus converting the localized string into the correct number value.
The second method is Number.localFormat(format). This method formats a decimal or currency value based on the current culture into a string.
So, for example, if the current culture was set to "fr-FR" the above code would output "2,75". Thus making use of the selected culture's defined number formatting properties.