Tisho_Todorov

05.FormattingNumbers

Oct 16th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. class FormattingNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please give us some numbers");
  8.        
  9.         Console.Write("Integer number a = ");
  10.         int a = int.Parse(Console.ReadLine());
  11.  
  12.         Console.Write("Floating-point number b = ");
  13.         double b = double.Parse(Console.ReadLine());
  14.  
  15.         Console.Write("Floating-point number c = ");
  16.         double c = double.Parse(Console.ReadLine());
  17.  
  18.         Console.Write("|{0,-10:X}|", a);    //pad left -10, X convert to hexadecimal
  19.         Console.Write(Convert.ToString(a, 2).PadLeft(10, '0') + "|"); //binary form
  20.        
  21.         Console.Write("{0,10:0.00}|", b);   //pad right 10
  22.  
  23.         Console.Write("{0,-10:0.000}|", c);
  24.         Console.WriteLine("See you next time");
  25.         Console.Title = "Created by T.Todorov";
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment