Windows Phone Developers

Saturday, May 8, 2010

How to format Currency (Pound/Dollar/Euro etc) using C#/VB.NET/Csharp Writeline function

Formatting Currency in C#/VB.NET/Csharp Writeline function

You can use .NET's Composite Formatting to format the currency as shown below

    Double Incentive = 234.45;
            Console.WriteLine("The agreed incentive in local currency is {0:C} ", Incentive);
        

If you want to convert it into dollars/pounds etc you need to change the culture info :

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
            Console.WriteLine("The agreed incentive in USD is {0:C} ", Incentive);


            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);
            Console.WriteLine("The agreed incentive in GBP is {0:C} ", Incentive);




The above code needs the following directives

using System.Threading;
using System.Globalization;
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005