mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-04-04 21:00:39 -04:00
Co-authored-by: Damian Stasik <920747+damianstasik@users.noreply.github.com> Co-authored-by: Roman Grinovski <roman.grinovski@gmail.com>
32 lines
783 B
Plaintext
32 lines
783 B
Plaintext
---
|
|
sidebar_label: tonumber
|
|
description: The tonumber function converts a value to a number.
|
|
---
|
|
|
|
# `tonumber` Function
|
|
|
|
`tonumber` converts its argument to a number value.
|
|
|
|
Explicit type conversions are rarely necessary in OpenTofu because it will
|
|
convert types automatically where required. Use the explicit type conversion
|
|
functions only to normalize types returned in module outputs.
|
|
|
|
Only numbers, `null`, and strings containing decimal representations of numbers can be
|
|
converted to number. All other values will produce an error.
|
|
|
|
## Examples
|
|
|
|
```
|
|
> tonumber(1)
|
|
1
|
|
> tonumber("1")
|
|
1
|
|
> tonumber(null)
|
|
null
|
|
> tonumber("no")
|
|
Error: Invalid function argument
|
|
|
|
Invalid value for "v" parameter: cannot convert "no" to number: string must be
|
|
a decimal representation of a number.
|
|
```
|