How to Round a Number to Two Decimal Places with Math.Round in C#
Math.Round(value, 2) rounds a number to two decimal places. Watch the halfway values: by default 2.125 becomes 2.12, not 2.13, unless you pass MidpointRounding.AwayFromZero.
Microsoft's reference for the decimal version, Math.Round(Decimal, Int32): Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. Fractional digits are the digits after the decimal point. A midpoint is a value exactly halfway between two possible results. The reference again: In a midpoint value, the value after the least significant digit in the result is precisely half way between two numbers. For example, 3.47500 is a midpoint value if it is to be rounded to two decimal places, and 7.500 is a midpoint value if it is to be rounded to an integer.
Syntax
decimal <rounded> = Math.Round(<value>, <decimals>);
decimal <rounded> = Math.Round(<value>, <decimals>, MidpointRounding.<mode>);
| Part | What it is |
|---|---|
Math.Round | The static method of the Math class that rounds a number |
<value> | The number to round: a decimal here. It also takes a double |
<decimals> | How many digits to keep after the decimal point: 2 for two decimal places |
MidpointRounding.<mode> | Optional: what to do with a midpoint, such as AwayFromZero. Without it, a midpoint goes to the even neighbour |
<rounded> | The rounded number. Math.Round returns it and doesn't change <value> |
The Example
A console app called MathRoundDecimals works out the average of three test scores, 78, 85 and 91, rounds it to two decimal places, and then rounds two midpoints, 2.125 and 2.135, with the default and with MidpointRounding.AwayFromZero.
Prerequisites
- The .NET 10 SDK.
dotnet --versionprints a version that starts with10.0.
Step 1: Create a Console App
dotnet new console -n MathRoundDecimals
cd MathRoundDecimals
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/MathRoundDecimals/MathRoundDecimals.csproj:
Determining projects to restore...
Restored /Users/you/source/MathRoundDecimals/MathRoundDecimals.csproj (in 42 ms).
Restore succeeded.
dotnet new console -n MathRoundDecimals creates a folder named MathRoundDecimals with a project file and a Program.cs, and cd moves into it. Everything this example uses is part of .NET, so there's no package to add. Open the folder in VS Code, or MathRoundDecimals.csproj in Visual Studio.
Step 2: Write the Code
Replace everything in Program.cs. First the average:
// The average of three test scores has a long tail of decimals.
decimal average = (78m + 85m + 91m) / 3;
Console.WriteLine($"Average: {average}");
The m after each number makes it a decimal. The three scores add up to 254, and 254 divided by 3 never ends, so the average has a long tail of decimals.
Then round it:
// Math.Round(value, 2) rounds the number itself to two decimal places.
decimal rounded = Math.Round(average, 2);
Console.WriteLine($"Rounded to 2 places: {rounded}");
Math.Round(average, 2) returns the average rounded to two decimal places, as a new decimal.
Last, the two midpoints:
// Halfway values: by default they go to the even neighbour.
decimal[] halfway = [2.125m, 2.135m];
foreach (decimal value in halfway)
{
decimal toEven = Math.Round(value, 2);
decimal awayFromZero = Math.Round(value, 2, MidpointRounding.AwayFromZero);
Console.WriteLine($"{value}: default {toEven}, AwayFromZero {awayFromZero}");
}
2.125 and 2.135 each sit exactly halfway between two numbers with two decimal places. The loop rounds each one twice: Math.Round(value, 2) uses the default, and Math.Round(value, 2, MidpointRounding.AwayFromZero) names the mode.
Step 3: Run It
Run it in VS Code's terminal, or press Ctrl+F5 in Visual Studio:
dotnet run
Average: 84.66666666666666666666666667
Rounded to 2 places: 84.67
2.125: default 2.12, AwayFromZero 2.13
2.135: default 2.14, AwayFromZero 2.14

The average, 84.66666666666666666666666667, became 84.67. The midpoints are where the modes differ. By default, 2.125 became 2.12 and 2.135 became 2.14: each went to the neighbour whose last digit is even. The reference calls this rounding to nearest even, or banker's rounding: Midpoint values are rounded to the nearest even number. For example, both 3.75 and 3.85 round to 3.8, and both -3.75 and -3.85 round to -3.8. With AwayFromZero, both went up, to 2.13 and 2.14: Midpoint values are rounded to the next number away from zero.
The Complete File

// The average of three test scores has a long tail of decimals.
decimal average = (78m + 85m + 91m) / 3;
Console.WriteLine($"Average: {average}");
// Math.Round(value, 2) rounds the number itself to two decimal places.
decimal rounded = Math.Round(average, 2);
Console.WriteLine($"Rounded to 2 places: {rounded}");
// Halfway values: by default they go to the even neighbour.
decimal[] halfway = [2.125m, 2.135m];
foreach (decimal value in halfway)
{
decimal toEven = Math.Round(value, 2);
decimal awayFromZero = Math.Round(value, 2, MidpointRounding.AwayFromZero);
Console.WriteLine($"{value}: default {toEven}, AwayFromZero {awayFromZero}");
}
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Expecting 2.125 to round to 2.13 | Math.Round(2.125m, 2) returned 2.12. The reference: By default, the Round method uses the round to nearest even convention. | Name the mode you want: Math.Round(2.125m, 2, MidpointRounding.AwayFromZero) returned 2.13 |
Calling Math.Round without keeping the result | Math.Round(price, 2); on a line of its own left price at 4.567 | Assign the result: after price = Math.Round(price, 2);, it printed 4.57 |
| Expecting two decimal places to always print two digits | Math.Round(2.5m, 2) printed 2.5, not 2.50. The reference says it for the version that takes a mode: If d has fewer fractional digits than decimals, d is returned unchanged. | Choose the digits when you print: with using System.Globalization;, rounded.ToString("0.00", CultureInfo.InvariantCulture) printed 2.50 |
FAQ
How do I always round up, or always round down?
Use one of the other three modes. They work on every value, not only on midpoints:
decimal value = 2.121m;
Console.WriteLine($"ToPositiveInfinity: {Math.Round(value, 2, MidpointRounding.ToPositiveInfinity)}");
Console.WriteLine($"ToNegativeInfinity: {Math.Round(value, 2, MidpointRounding.ToNegativeInfinity)}");
Console.WriteLine($"ToZero: {Math.Round(-2.129m, 2, MidpointRounding.ToZero)}");
ToPositiveInfinity: 2.13
ToNegativeInfinity: 2.12
ToZero: -2.12
ToPositiveInfinity took 2.121 up to 2.13, ToNegativeInfinity took it down to 2.12, and ToZero cut -2.129 to -2.12. The reference: In .NET Core 3.0 and later versions, three additional rounding strategies are available through the MidpointRounding enumeration. These strategies are used in all cases, not just for midpoint values as MidpointRounding.ToEven and MidpointRounding.AwayFromZero are.
Should I round a double or a decimal?
Round a decimal when the digits after the point matter, as with money. A double holds most decimal fractions only approximately:
using System.Globalization;
double asDouble = 2.675;
decimal asDecimal = 2.675m;
Console.WriteLine($"double 2.675 -> {Math.Round(asDouble, 2)}");
Console.WriteLine($"decimal 2.675 -> {Math.Round(asDecimal, 2)}");
Console.WriteLine($"What the double really holds: {asDouble.ToString("G17", CultureInfo.InvariantCulture)}");
double 2.675 -> 2.68
decimal 2.675 -> 2.68
What the double really holds: 2.6749999999999998
Both rounded to 2.68 on .NET 10, but the double doesn't hold 2.675: it holds 2.6749999999999998, just below the midpoint. .NET 11 changes Math.Round for double to round that exact value, and its breaking-change notice shows the same case: For example, 655.925 is stored as 655.924999999999954525…, which is below the 655.925 midpoint, so the correct result is 655.92. It explains: double and float are binary floating-point types and can't exactly represent most decimal fractions. For exact decimal rounding of decimal quantities, prefer Decimal.
Conclusion
Math.Round(value, 2) rounds a number to two decimal places and returns the result, so assign it. Midpoints go to the even neighbour unless you pass a MidpointRounding mode: AwayFromZero to take 2.125 up to 2.13, and ToPositiveInfinity or ToNegativeInfinity to always go up or down. Round decimal values when the digits matter, and choose how many digits to show when you print.
Additional Resources
Math.RoundMethod — every overload, midpoint values and rounding strategies.MidpointRoundingEnum — the five rounding modes.- Math.Round and MathF.Round return correctly rounded results — the .NET 11 change for
doubleandfloat. - Custom numeric format strings — formats such as
0.00for printing a number.
