Sometimes , you might want to specify the maximum number of decimal places that will be displayed to the user . For example , assume that the input value is 7890.3456 and if you want to display only 7890.34 (Note : only 2 decimal places) , you can use the format specifier “F2” to display 2 decimal places.
How to Specify the Number of Decimal Places for a Number in C# ?
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; namespace Ginktage { internal class Program { private static void Main(string[] args) {
double InputValue = 7890.3456; Console.WriteLine(InputValue.ToString("F2", CultureInfo.InvariantCulture)); Console.ReadLine(); } } }