Skip to content

Newbie question relating to number formatting.

Pawel

Asked May 28, 2006, 2:44 PM EDT1 answer
Share
LinkedInX

Brief Information: Salary program that outputs differently based on tax brackets. Completed for school

Problem: Numbers need to be right aligned instead of left. I' ve just been introduced to c# so i dont know if there are any text formatting tricks :)  If additional information is needed, please say so. Any help on this matter is appreciated. Thanks

(all variables are defined as floats, I suspect I may have to parse them to strings to align them evenually to the right)



Output: 

Console.WriteLine("Salary Calculator" );

Console.WriteLine("" );

Console.WriteLine("Enter the gross salary of the employee:" +grossSalary );

Console.WriteLine("" );

Console.WriteLine("Gross Salary $" +grossSalary);

Console.WriteLine("Canadian Pension Plan - $" +CalculateCPP(grossSalary));

Console.WriteLine("Employment Insurance - $" +CalculateEI(grossSalary));

Console.WriteLine("Provinical Tax - $" +CalculatePTax(grossSalary));

Console.WriteLine("Federal Tax - $" +CalculateFTax(grossSalary));

Console.WriteLine(" -------------");

Console.WriteLine("Net Salary $" +netSalary);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi, I believe your looking to output all values lined up as if in a column? What you can do is use a tab by adding \t to your output string, such as: Console.WriteLine("My first value: $\t"+value); or to make it align two tab spaces just use '\t\t' and so on. You also dont need to have: Console.WriteLine(""); to generate a new line, instead just add \n to the previous string, such as: Console.WriteLine("My Text\n"); the \n and \t are escaped characters and do not get printed. Also if you need to read in your value through the command line use: string userInput = ConsoleReadLine(); then convert the userInput into your float. Darren
    0