# CDec
{: .no_toc }

Coerces an expression to a **Decimal**.

Syntax: **CDec(** *expression* **)**

*expression*
: *required* Any valid string or numeric expression. The range for zero-scaled numbers (no decimal places) is `±79,228,162,514,264,337,593,543,950,335`. For numbers with 28 decimal places, the range is `±7.9228162514264337593543950335`. The smallest possible non-zero number is `0.0000000000000000000000000001`.

The return type is **Decimal**.

> [!NOTE]
> In VBA, **CDec** does not return a discrete data type; it always returns a **Variant** whose value has been converted to a **Decimal** subtype. In twinBASIC, **Decimal** is a full first-class data type, so **CDec** returns a **Decimal** directly. The result can be assigned to a **Variant** for VBA-compatible behavior.

**CDec** is the internationally aware alternative to [**Val**](/tB/Modules/Conversion/Val.md) for converting a string to a numeric type.

### Common Errors

| Error | When |
|---|---|
| [6 (`&H6`)](/Reference/Run-time-Errors.md#6), *Overflow* | *expression* is less than -79,228,162,514,264,337,593,543,950,335 or greater than 79,228,162,514,264,337,593,543,950,335 |
| [13 (`&HD`)](/Reference/Run-time-Errors.md#13), *Type mismatch* | *expression* is a string that does not hold a number (a zero-length string included) |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *expression* is **Null** |

### Example

This example uses the **CDec** function to convert a numeric value to a **Decimal**.

```tb check_build
Dim MyDecimal As Decimal, MyCurr As Currency
MyCurr = 10000000.0587               ' MyCurr is a Currency.
MyDecimal = CDec(MyCurr)             ' MyDecimal is a Decimal.
```

### See Also

- [CCur](/tB/Modules/Conversion/CCur.md), [CDbl](/tB/Modules/Conversion/CDbl.md), [CSng](/tB/Modules/Conversion/CSng.md), [ValDec](/tB/Modules/Conversion/ValDec.md) functions
