Tuesday, March 18, 2008

Format currency using Globalization .NET

There are some elegant way to format the currency such as

String.Format(“{0:c}”,100000”)

The output will be RM100,000.00 if your web.config file set as

<*system.web*>
<*globalization uiCulture="en" culture="en-MY" /*>

However this will not throw you an error if you are using windows vista. such as
The tag contains an invalid value for the 'culture' attribute.
if there is an error please refer to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemGlobalizationCultureInfoClassTopic.asp to find out your own culture code.

in this case i should change it to

<*globalization uiCulture="ms" culture="ms-MY" /*>

....
If you set the culture to “en-US” then the output will changed to
$100,000.00
You can check your currency symbol by using this code

System.Globalization.RegionInfo myRI2 = new System.Globalization.RegionInfo(new CultureInfo("en-my", false).LCID);
Console.Write(myRI2.CurrencySymbol);

For more information on setting the culture for specific to your country, please refer the code from this website:
http://msdn2.microsoft.com/en-us/library/system.globalization.regioninfo.aspx

Alternatively, you can specify use string. Format (“{0:$#,##0.##}”,50000), you can replace the ‘$’ whaterver you like. however this is not a good practice.

3 comments:

Anonymous said...

Nice post and this post helped me alot in my college assignement. Thanks you seeking your information.

Anonymous said...

i without a doubt love your writing taste, very attractive.
don't give up and keep posting for the reason that it just simply very well worth to read it.
impatient to see far more of your articles, regards ;)

Anonymous said...

, melyssa ford playboy, >:-DDD, kiele sanchez nude, lizi, bridget regan nude, >:(((,