Programming Steps:
1. Either you can use String.Format() function to format in given format.
2. Or you can directly use Console.WriteLine("{0:0.00}", 100.0) to print number in a format.
Output of program:
Code for Formatting number to two decimal places:
using System;
using System.Text;
namespace TestConsole
{
class DecimalFormat
{
static void Main(string[] args)
{
Console.WriteLine(String.Format("{0:0.00}", 163.48967));
Console.WriteLine(String.Format("{0:0.00}", 173.4));
Console.WriteLine(String.Format("{0:0.00}", 193.0));
//or
Console.WriteLine("{0:0.00}", 100.0);
Console.ReadLine();
}
}
}
No comments:
Post a Comment