Advertisement
stanevplamen

02.08.11.StringFormat

Aug 23rd, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Threading;
  4.  
  5. class NumberPrint
  6. {
  7.     static void Main()
  8.     {
  9.         Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
  10.         Console.Write("Please enter a number: ");
  11.         decimal userNumber = decimal.Parse(Console.ReadLine());
  12.  
  13.         string formatDecimal = String.Format("{0,15}| type decimal", userNumber);
  14.         string formatHex = String.Format("{0,15}| hex presentation of the int part", Convert.ToString((int)userNumber, 16).ToUpper());
  15.         string formatPercentage = String.Format("{0,15:P}| as percentage", userNumber);
  16.         string formatScient = String.Format("{0,15:E7}| as scientific notation", userNumber);
  17.  
  18.         string finalStr = String.Format("{0}\n{1}\n{2}\n{3}", formatDecimal, formatHex, formatPercentage, formatScient);
  19.         Console.WriteLine(finalStr);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement