Round C# Double to 2 Decimals

In C#, you can use the ToString() method or format strings to keep two decimal places.

Option 1: Utilize the ToString() method.

double number = 3.1415926;
double roundedNumber = Math.Round(number, 2);
Console.WriteLine(roundedNumber.ToString("0.00")); // 输出 3.14

Option 2: Utilize formatted strings.

double number = 3.1415926;
Console.WriteLine("{0:0.00}", number); // 输出 3.14

Both methods can be used to round a double type number to two decimal places.

bannerAds