C# Float vs Double vs Decimal: Key Differences
Compare C# float, double, and decimal: precision, range, memory, and performance tradeoffs, plus practical guidance on choosing the right numeric type.

When you need to store a numeric value in C#, the choice between float, double, and decimal affects precision, range, memory usage, and runtime cost. The key difference is how each type represents numbers internally, and that representation determines where each type is appropriate.
The Three Types at a Glance
float is a 32-bit IEEE 754 single-precision value backed by System.Single. double is a 64-bit IEEE 754 double-precision value backed by System.Double. decimal is a 128-bit value backed by System.Decimal and uses a base-10 representation rather than a binary one.
| Type | Size | Precision | Base | Typical use |
|---|---|---|---|---|
| float | 32 bits | ~7 digits | 2 | Graphics, sensors, game physics |
| double | 64 bits | ~15-17 digits | 2 | Scientific computation, general math |
| decimal | 128 bits | 28-29 digits | 10 | Financial and monetary calculations |
The base matters more than most developers expect. float and double store values as binary fractions, so many decimal values that look simple, like 0.1, cannot be represented exactly. decimal represents values with decimal scaling, which matches how money and most human-readable quantities are expressed.
Precision and Range Differences
The practical difference between float and double is the number of significant digits they can hold. float gives roughly 7 significant digits, double gives roughly 15 to 17. If you add 0.1f to 1.0f repeatedly, the accumulated error becomes visible after a few operations. double reduces that error but does not eliminate it.
decimal holds 28 to 29 significant digits and represents values like 0.1m exactly. That exactness is why decimal is the standard choice for currency amounts and financial calculations where rounding rules matter.
The range also differs. float can represent values up to about 3.4 × 10^38, double up to about 1.7 × 10^308, and decimal up to about 7.9 × 10^28. For most application code, range is rarely the deciding factor, but it matters if you work with very large or very small magnitudes.
Declaring and Using Each Type
C# uses suffixes to distinguish real-number literals. A real-number literal without a suffix is treated as double; integer literals have their own default types.
float f = 3.14f;
double d = 3.14;
decimal m = 3.14m;The f suffix forces a float literal, and the m suffix forces a decimal literal. Without these suffixes, 3.14 is a double, and assigning it to a float or decimal variable requires an explicit cast. That cast is not always safe: a double may have more precision than float can hold, and it may be outside decimal's range.
When you write arithmetic that mixes types, C# promotes the result to the wider type. Mixing float and double produces a double. Mixing decimal with float or double is not allowed without an explicit cast because the base representations are incompatible.
float a = 1.5f;
double b = 2.5;
// double result = a + b; // valid, result is double
decimal price = 19.99m;
// decimal result = price + b; // compile error
decimal total = price + (decimal)b; // explicit conversionThe explicit conversion from double to decimal can throw an OverflowException if the value is outside decimal's range, so it should be used deliberately rather than as a default pattern.
Why decimal Matters for Financial Calculations
Money calculations can go wrong with float and double because binary fractions cannot represent most decimal amounts exactly. For example, a tax calculation with double can have a value such as 19.990000000000002 internally instead of exactly 19.99. The error is small in a single operation but compounds across many transactions, invoices, or ledger entries.
decimal avoids that class of error because it represents values with decimal scaling rather than as binary approximations. Up to its 28-29 significant digits, values like 19.99m are stored exactly. That is why decimal is the default recommendation for currency, interest rates, tax amounts, and any value that must round to a specific number of decimal places.
The tradeoff is that decimal arithmetic is significantly slower than double arithmetic because the runtime performs base-10 operations rather than using the hardware floating-point unit directly. For a few hundred calculations per request, the difference is irrelevant. For tight loops processing millions of values, it can become the bottleneck.
When float and double Are the Right Choice
float and double are appropriate when the value is a measurement or a result of a computation that is inherently approximate. Sensor readings, audio samples, graphics coordinates, physics simulations, and most scientific calculations do not need exact decimal representation. They need speed and range.
double is the default choice for general-purpose floating-point math in C# because it matches the precision of the double type used by most numerical libraries and the .NET runtime's math functions. float is useful when memory bandwidth matters, such as storing large arrays of positions or colors in a graphics pipeline, where the reduced precision is acceptable.
A common mistake is using decimal for performance-critical numerical code that does not involve money. A physics engine or a machine-learning inference loop that uses decimal will run slower and use more memory without gaining correctness, because the inputs are already approximate.
Performance and Memory Tradeoffs
float uses 4 bytes per value, double uses 8 bytes, and decimal uses 16 bytes. In a large array or a hot loop, that difference affects cache behavior and memory pressure. decimal also requires more CPU work per operation because it is not backed by a hardware floating-point unit in the same way.
The mechanism is straightforward: float and double operations map to the CPU's native floating-point instructions, while decimal operations are implemented in software. That does not mean decimal is unusable, only that the cost is measurable when operations are repeated at scale. For typical business logic, the difference is negligible.
Common Pitfalls with Equality and Rounding
Comparing float or double values with == is unreliable because of representation error. Two values that should be equal can differ by a tiny amount.
double x = 0.1 + 0.2;
Console.WriteLine(x == 0.3); // FalseThe value 0.1 + 0.2 is stored as a binary approximation, and 0.3 is a different binary approximation. The comparison fails even though the values look identical when printed. A tolerance-based comparison is the standard workaround:
double x = 0.1 + 0.2;
double tolerance = 1e-9;
bool equal = Math.Abs(x - 0.3) < tolerance;decimal does not have this problem for values that fit within its precision, which is why equality comparisons on monetary amounts are safe with decimal. Rounding behavior is also important. Math.Round uses banker's rounding by default for both double and decimal, and you can pass a MidpointRounding argument to select the rounding mode. Because decimal values are exact, the rounding step operates on the actual value rather than on a binary approximation. When exact rounding matters, decimal gives you predictable control.
Choosing the Right Type in Practice
The decision follows a simple rule. Use decimal when the value represents money, quantities that must round exactly, or any value where base-10 semantics are required. Use double for general numerical computation, scientific formulas, and any value that is a measurement. Use float when memory size or bandwidth is the dominant constraint and the reduced precision is acceptable.
These differences are not about which type is best in general. They are about matching the type's representation to the semantics of the data. A financial ledger and a physics simulation have different correctness requirements, and the numeric type should reflect that.
Try matching browser tools
All toolsSmall utilities that fit C# work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related C# guides
All C# guidesC# Dispose vs Destructor: Key Differences Explained
c# dispose vs destructor: Understand the difference between Dispose and destructors in C#, when each runs, and how to manage unmanaged resources correctly.
C# Variable Declaration: Syntax and Practical Usage
Learn how to declare variables in C# with explicit types, var, and nullable annotations, and understand how defaults, scope, and readability affect your choices.
C# Primary Constructors for Classes: Syntax and Usage
Learn how to use C# primary constructors for classes: syntax, initialization, dependency injection, and limitations with practical examples.
C# IComparer: Custom Sorting with IComparer<T>
Learn how to implement IComparer<T> in C# to define custom sort order for arrays and lists, handle nulls, and avoid common performance pitfalls.
More in C#
All C# guidesThe guides filed next to this one in C#, in library order.