How to format decimal places and align numbers with spaces in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        Console.WriteLine("\"" + (String.Format("{0,12:0.0}", 1238.4567)) + "\"");
        
        Console.WriteLine("\"" + String.Format("{0,-12:0.0}", 1238.4567) + "\"");
        
        Console.WriteLine("\"" + String.Format("{0,12:0.0}", -1238.4567) + "\"");
        
        Console.WriteLine("\"" + String.Format("{0,-12:0.0}", -1238.4567) + "\"");
    }
}




/*
run:

"      1238.5"
"1238.5      "
"     -1238.5"
"-1238.5     "

*/

 



answered Apr 5, 2022 by avibootz

Related questions

1 answer 164 views
1 answer 125 views
4 answers 210 views
210 views asked Apr 5, 2022 by avibootz
1 answer 234 views
1 answer 207 views
...