Formatting Negative Numbers - CSharp Language Basics

CSharp examples for Language Basics:Data Type

Description

Formatting Negative Numbers

Demo Code

using System;/*from ww  w  .j  av a2  s  .c  o m*/
class ThreeWay
{
   public static void Main()
   {
      Console.WriteLine("\nExample 1...");
      for ( int x = -100; x <= 100; x += 100 )
      {
         Console.WriteLine("{0:000;-00000;'0'}", x);
      }
      Console.WriteLine("\nExample 2...");
      for ( int x = -100; x <= 100; x += 100 )
      {
         Console.WriteLine("{0:Pos: 0;Neg: -0;Zero}", x);
      }
      Console.WriteLine("\nExample 3...");
      for ( int x = -100; x <= 100; x += 100 )
      {
         Console.WriteLine("{0:You Win!;You Lose!;You Broke Even!}", x);
      }
   }
}

Result


Related Tutorials