Quantcast
Channel: Formatting C# output - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Answer by user156862 for Formatting C# output

$
0
0

Take a look at http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

This should do what you want:

        int num = 10;

        Console.WriteLine(num.ToString("0#"));

        Console.ReadLine();

The string that is passed to the ToString method "0#" has the following meaning:

0 - 0 place holder, this will be replaced with relevant digit if one exists
# - digit place holder.

So if num is 0, 00 will be written to the console but if num is 10, 10 will be written to the console.


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>