In C#, Convert.ToDecimal returns a decimal—a precise base-10 floating type often used for money.
It accepts digit strings and other numeric types. Prefer decimal over double when exact fractional decimals matter.
This is a static member of System.Convert. You call it with the type name, such as Convert.ToDecimal(...). Convert is the everyday API for converting between common CLR types in C#.
Syntax
Convert text or numbers into decimal.
C#
decimal a = Convert.ToDecimal("19.99");
decimal b = Convert.ToDecimal(3);
decimal c = Convert.ToDecimal(2.5);
Call
What it does
Convert.ToDecimal("19.99")
Money-like digit string.
Convert.ToDecimal(3)
Integer widened to decimal.
null → 0. Bad format → FormatException. Out of decimal range → OverflowException.
Library declarations
C#
public static decimal ToDecimal(string? value);
public static decimal ToDecimal(double value);
public static decimal ToDecimal(object? value);
Parameters
Parameter
Description
value
Required. Text or number to convert.
Return Value
Return Value
Description
decimal
Precise decimal result.
C# Examples
Example 1 — Parse a Price
Read a decimal amount from text.
C#
using System;
class Program {
static void Main() {
decimal price = Convert.ToDecimal("19.99");
Console.WriteLine(price);
Console.WriteLine(price * 2);
}
}
Output
19.99
39.98
How It Works
Exact tenths. decimal keeps 19.99 precisely.
Double it. Multiplication stays on decimal math.
Text source. Useful when prices arrive as strings.
Null → 0. Missing values become zero with Convert.
Example 2 — Add Converted Amounts
Convert two strings and add them.
C#
using System;
class Program {
static void Main() {
decimal a = Convert.ToDecimal("10.25");
decimal b = Convert.ToDecimal("0.75");
Console.WriteLine(a + b);
}
}
Output
11.00
How It Works
Two parses. Each string becomes decimal first.
Exact sum. 10.25 + 0.75 equals 11.00.
Display. Console may show trailing zeros for scale.
Avoid double. Binary floating types can drift on money.
Example 3 — Widen a Double
Convert a double literal into decimal.
C#
using System;
class Program {
static void Main() {
double approx = 2.5;
decimal exact = Convert.ToDecimal(approx);
Console.WriteLine(exact);
Console.WriteLine(exact * 4);
}
}
Output
2.5
10.0
How It Works
Start as double. 2.5 is a binary floating value.
ToDecimal. Convert copies it into decimal form.
Scale up. Multiplying by 4 yields 10.
Be aware. Some doubles have binary noise before conversion.
Frequently Asked Questions
Decimal is base-10 and better for currency and exact fractional totals.
Yes for typical ToDecimal overloads.
String parsing follows culture; "19,99" may be valid in some locales.
Yes—values outside decimal range throw OverflowException.
Parse throws on null; Convert returns 0. Both throw on bad text.