C# Convert ToDecimal() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Convert

Definition

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);
CallWhat 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

ParameterDescription
valueRequired. Text or number to convert.

Return Value

Return ValueDescription
decimalPrecise 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);
    }
}

How It Works

  1. Exact tenths. decimal keeps 19.99 precisely.
  2. Double it. Multiplication stays on decimal math.
  3. Text source. Useful when prices arrive as strings.
  4. 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);
    }
}

How It Works

  1. Two parses. Each string becomes decimal first.
  2. Exact sum. 10.25 + 0.75 equals 11.00.
  3. Display. Console may show trailing zeros for scale.
  4. 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);
    }
}

How It Works

  1. Start as double. 2.5 is a binary floating value.
  2. ToDecimal. Convert copies it into decimal form.
  3. Scale up. Multiplying by 4 yields 10.
  4. 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.

Next: ToDouble()

Convert a value to double—64-bit floating-point numbers with System.Convert.

ToDouble() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful