Advertisement
NPSF3000

Types, Accuracy and String Formatting.

Feb 21st, 2012
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace TypesForMoney
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int i = 1;
  13.             float f = 1f;
  14.             double d = 1d;
  15.             decimal m = 1m;
  16.  
  17.             Console.WriteLine(i);  //1
  18.             Console.WriteLine(f);  //1
  19.             Console.WriteLine(d);  //1
  20.             Console.WriteLine(m);  //1
  21.            
  22.             Console.WriteLine(i.ToString("C"));  //$1.00
  23.             Console.WriteLine(f.ToString("C"));  //$1.00
  24.             Console.WriteLine(d.ToString("C"));  //$1.00
  25.             Console.WriteLine(m.ToString("C"));  //$1.00
  26.  
  27.             i /= 10;
  28.             f /= 10;
  29.             d /= 10;
  30.             m /= 10;
  31.  
  32.             Console.WriteLine(i.ToString("G20"));  //0
  33.             Console.WriteLine(f.ToString("G20"));  //0.100000001
  34.             Console.WriteLine(d.ToString("G20"));  //0.10000000000000001
  35.             Console.WriteLine(m.ToString("G20"));  //0.1
  36.  
  37.             Console.Read();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement