Home » C#

C# | Printing numbers with text (minus or zero) using String.Format() method

C# | String.Format() method with Example: Here, we are going to learn how to print text (minus or zero) with the numbers in C#?
Submitted by IncludeHelp, on November 01, 2019

To print the text (minus or zero) with the numbers, we can use String.Format() method of String class in C#.

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Demo for zero and negative integer number:");

            Console.WriteLine(String.Format("{0:#;minus #}" ,  256));
            Console.WriteLine(String.Format("{0:#;minus #}" , -256));
            Console.WriteLine(String.Format("{0:#;minus #;zero}" ,    0));
            
            Console.WriteLine();  
        }
    }
}

Output

Demo for zero and negative integer number:
256
minus 256
zero

In the above program, we printed the text "minus 256" in place of -256 and print "zero" in place of 0.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.