Format Price in decimal type - CSharp Language Basics

CSharp examples for Language Basics:Data Type Format

Description

Format Price in decimal type

Demo Code

using System;//from  w w  w.j av  a  2 s .  com
using System.ComponentModel;
public class FormatPrice
{
   static void Main()
   {
      decimal price = 95.25m;
      decimal tip = price * 0.2m; // 20% tip
      Console.WriteLine("Price: {0,9:C}", price);
      Console.WriteLine("Tip:   {0,9:C}", tip);
      Console.WriteLine("Total: {0,9:C}", price + tip);
   }
}

Result


Related Tutorials