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

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

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

  1. Double Incentive = 234.45;
  2. Console.WriteLine(“The agreed incentive in local currency is {0:C} ”, Incentive);
    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 :

  1. Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-US”, false);
  2. Console.WriteLine(“The agreed incentive in USD is {0:C} ”, Incentive);
  3. Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-GB”, false);
  4. Console.WriteLine(“The agreed incentive in GBP is {0:C} ”, Incentive);
            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

  1. using System.Threading;
  2. using System.Globalization;
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

Posted by Shasur at 12:37 AM
Labels: , ,
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.