How do I convert a decimal to an int in C?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In C#, converting a decimal to an int is not just a syntax question. You also need to decide what should happen to the fractional part and what should happen when the value is outside the int range.
Different conversion methods express different intent. Some truncate, some round, and all of them can fail if the number is too large or too small to fit in a 32-bit integer.
Direct Cast Truncates the Fractional Part
The simplest conversion is an explicit cast.
This prints 12.
The cast does not round to the nearest whole number. It removes the fractional part. For negative values, it truncates toward zero, so -12.99m becomes -12.
Use this only when truncation is exactly what you want.
Convert.ToInt32 Rounds Instead of Truncating
If you want normal rounding behavior, use Convert.ToInt32.
This rounds the value rather than chopping off the decimal part.
That difference is important in financial or measurement code where 12.9m becoming 12 may be wrong for the business rule.
Use Math Methods When the Rule Must Be Explicit
Sometimes you need to say exactly how rounding should behave before converting.
This makes the rule visible in the code:
- '
Floorgoes down' - '
Ceilinggoes up' - '
Rounduses rounding logic'
That is often clearer than relying on teammates to remember how a direct cast behaves.
Watch for Overflow
An int in C# can only hold values between -2,147,483,648 and 2,147,483,647.
If the decimal falls outside that range, the conversion throws an exception.
This is why numeric conversion should not be treated as harmless. Range matters.
Picking the Right Conversion Rule
Ask these two questions first:
- should the fractional part be truncated or rounded?
- what should happen if the number does not fit?
Common choices:
- cast when truncation is intended
- '
Convert.ToInt32when rounding is intended' - '
Math.Floor,Math.Ceiling, orMath.Roundwhen the rule must be explicit before conversion'
Once you answer those questions, the code choice becomes obvious.
Why decimal Is Special
decimal is often used for money and exact base-10 arithmetic. That means converting it to int can silently throw away information.
For example, 19.99m is not “almost 20” in every business context. In some systems it is a price that must stay exact, and converting it to an integer at all is a design mistake.
So the best conversion code is sometimes no conversion code. If the fractional part matters, keep the value as decimal.
Common Pitfalls
A common mistake is casting when the real requirement was rounding. That bug can remain hidden until edge cases such as 12.9m or -12.9m show up.
Another mistake is forgetting about overflow. A conversion that works fine in tests may throw in production when larger inputs appear.
Developers also sometimes convert monetary values to int too early and lose cents or other fractional precision that the domain actually needs.
Finally, be explicit about negative values. Truncation toward zero is not the same thing as always rounding down.
Summary
- A direct cast from
decimaltointtruncates the fractional part. - '
Convert.ToInt32rounds instead of truncating.' - Use
Math.Floor,Math.Ceiling, orMath.Roundwhen the rule must be explicit. - Any conversion can throw if the value is outside the
intrange. - Pick the conversion method based on business rules, not just on which syntax is shortest.

