How to Specify the Number of Decimal Places for a Double value in C# ?
Below is a sample code snippet that demonstrates how the developers can specify the number of decimal places for a number declared as double in C#.
How to Specify the Number of Decimal Places for a Double value in C# ?
C#
x
20
20
1
using System;
2
using System.Collections.Generic;
3
using System.Globalization;
4
using System.Linq;
5
using System.Text;
6
7
namespace AbundantcodeConsoleApp
8
{
9
internal class Program
10
{
11
private static void Main(string[] args)
12
{
13
// How to Specify the Number of Decimal Places for a Double value in C# ?
14
double Input = 1007.8675;
15
Console.WriteLine(Input.ToString("F2", CultureInfo.InvariantCulture));
16
Console.ReadLine();
17
}
18
}
19
20
}

Leave Your Comment