# ValDec
{: .no_toc }

Returns the numbers contained in a string as a **Decimal** value.

Syntax: **ValDec(** *string* **)**

*string*
: *required* Any valid string expression.

The return type is **Decimal**.

> [!NOTE]
> **ValDec** is a twinBASIC extension. It behaves like [**Val**](/tB/Modules/Conversion/Val.md) but returns a **Decimal** instead of a **Double**, preserving the full precision of values that **Val** would round.

The **ValDec** function follows the same parsing rules as [**Val**](/tB/Modules/Conversion/Val.md): it stops reading the string at the first character that it can't recognize as part of a number, ignores blanks, tabs, and linefeed characters, and recognizes the radix prefixes `&O` (octal) and `&H` (hexadecimal).

> [!NOTE]
> **ValDec** recognizes only the period (`.`) as a valid decimal separator. When different decimal separators are used, as in international applications, use [**CDec**](/tB/Modules/Conversion/CDec.md) instead.

### Common Errors

| Error | When |
|---|---|
| [6 (`&H6`)](/Reference/Run-time-Errors.md#6), *Overflow* | *string* holds a number outside the range of a **Decimal** |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *string* is **Null** |

### Example

This example uses the **ValDec** function to parse a string into a **Decimal**.

```tb check_build
Dim MyDec As Decimal
MyDec = ValDec("123.4567890123456789")    ' Full precision retained.
```

### See Also

- [Val](/tB/Modules/Conversion/Val.md), [CDec](/tB/Modules/Conversion/CDec.md), [CDbl](/tB/Modules/Conversion/CDbl.md) functions
