C# decimal for Money: Choose a Rounding Rule Before You Calculate
If a C# program calculates prices, tax or account balances, decimal is usually a better starting point than double. But choosing the type does not decide when to round or what to do when a value lands halfway between two cents. Those are business rules, and they should be visible in the code.

Editorial illustration: the data type helps, but the rounding policy still needs an explicit decision.
Summary
- Use
decimalfor decimal quantities such as currency amounts; its base-10 representation can represent values like0.1mexactly. - Decide where rounding occurs and choose a midpoint rule that matches the domain or regulation.
- Store currency and scale/currency code deliberately;
decimalalone does not enforce two decimal places or define a complete money model.
Why double surprises in financial calculations
double uses binary floating-point. Many decimal fractions, including 0.1, have no exact finite binary representation, so a calculation may carry a small approximation. That behavior is useful for scientific and graphics work where range and speed can matter, but it can make currency comparisons and totals confusing.
C#’s decimal type represents decimal fractions using a scaled integer representation. A decimal literal needs the m suffix because a literal such as 19.99 is a double by default:
double approximatePrice = 19.99; // double literal
decimal unitPrice = 19.99m; // decimal literal
The type is part of .NET’s numeric system and is available in ordinary C# projects; no special package is required. Microsoft’s documentation notes that decimal is suitable when precision is determined by digits after the decimal point, including currency and interest-rate calculations. It has a smaller range and higher memory cost than double, so it is not the right default for every numeric problem.
Calculate first, round at a named boundary
Imagine a checkout applies a 7.5% discount to three items and then calculates tax. Should each line be rounded to cents before summing, or should the order total be rounded after the calculation? The answer can vary by jurisdiction, accounting policy and payment processor. Rounding after every intermediate operation can produce a different result from rounding only the final amount.
Make the boundary explicit in a helper:
using System;
decimal subtotal = 3 * 19.99m;
decimal discountRate = 0.075m;
decimal discountedSubtotal = subtotal * (1m - discountRate);
decimal taxRate = 0.06m;
decimal tax = discountedSubtotal * taxRate;
decimal payable = decimal.Round(
discountedSubtotal + tax,
2,
MidpointRounding.ToEven);
Console.WriteLine(payable.ToString("C",
System.Globalization.CultureInfo.GetCultureInfo("en-MY")));
This example demonstrates one possible policy, not a claim that every Malaysian transaction should use it. The culture controls formatting such as currency symbol and separators; it does not determine the legal or accounting rounding rule. Confirm the policy with the relevant business requirements before applying it to invoices or financial records.
decimal.Round(value, digits) uses midpoint-to-even behavior by default. Midpoint-to-even chooses the nearest even final digit when the value is exactly halfway, which can reduce systematic bias across many operations. Some business rules instead require midpoint-away-from-zero. If that is the approved rule, pass it explicitly:
decimal rounded = decimal.Round(
amount,
2,
MidpointRounding.AwayFromZero);
Do not pick a rule because its name “sounds right.” Write down the expected outcome for positive and negative midpoint examples, then add tests for those examples.
Keep rounding policy out of presentation code
Formatting a value with "C" displays it as currency, but it does not change the stored amount or round the calculation to two decimal places. Likewise, formatting with "F2" is not a substitute for a domain rounding decision. Keep the numeric amount unformatted while calculating; format it at the UI or report boundary using an explicit culture.
A simple method makes the policy easier to test:
static decimal RoundForSettlement(decimal amount) =>
decimal.Round(amount, 2, MidpointRounding.ToEven);
The function name should describe why the rounding occurs. If line items and final settlement use different approved rules, name and test each boundary separately rather than hiding everything in a generic RoundMoney helper.
What decimal cannot solve by itself
- Currency identity:
10.00mdoes not tell you whether the amount is MYR, USD or another currency. Carry a currency code alongside the value. - Currency scale: not all currencies use two minor-unit digits, and internal calculations may need more precision than final display.
- Overflow:
decimalhas a bounded range. Large values or repeated multiplication can throwOverflowException. - Mixing numeric types: C# does not implicitly mix
decimalanddoublein arithmetic. Avoid converting adoubleresult intodecimallate and assuming its earlier approximation disappears. - Distributed consistency: database column precision, JSON serialization, payment gateways and other services must agree on scale and rounding. Test the complete path.
For many applications, storing a decimal amount plus an ISO currency code is sufficient. In a large financial domain, a dedicated money type may make invalid combinations harder to represent. Either way, preserve exact inputs and document the chosen conversion and rounding points.
A small test matrix
For the approved policy, test values just below, at and just above a midpoint, for both signs. Also test the smallest supported unit, a value with more fractional digits than expected, and a value near the allowed maximum. For midpoint-to-even at two digits, 1.245m and 1.255m are useful examples because they exercise different retained digits. Confirm results in code rather than relying on how a formatted string looks.
When porting a calculation, compare the old and new results over representative data. A changed result may reveal a previous floating-point approximation, a different rounding boundary, or a mismatch between application and database rules. Do not “correct” a difference without finding which policy the system is supposed to implement.
My Take
The important choice is not simply decimal versus double; it is making financial assumptions inspectable. Use decimal for decimal-valued money, name the rounding boundary, and write the expected midpoint behavior into tests. That gives the next developer something concrete to review.
Bottom Line
Start currency calculations with decimal literals and variables. Round only at a defined business boundary, pass the MidpointRounding rule explicitly, and keep formatting separate from arithmetic. Then verify the same scale and policy in storage and downstream payment systems.
Sources
- Microsoft Learn: Floating-point numeric types
- Microsoft Learn:
decimaltype - Microsoft Learn:
Decimal.Round - Microsoft Learn:
MidpointRounding