github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/tonumber.html.md (about) 1 --- 2 layout: "functions" 3 page_title: "tonumber - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-conversion-tonumber" 5 description: |- 6 The tonumber function converts a value to a number. 7 --- 8 9 # `tonumber` Function 10 11 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 12 earlier, see 13 [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html). 14 15 `tonumber` converts its argument to a number value. 16 17 Explicit type conversions are rarely necessary in Terraform because it will 18 convert types automatically where required. Use the explicit type conversion 19 functions only to normalize types returned in module outputs. 20 21 Only numbers and strings containing decimal representations of numbers can be 22 converted to number. All other values will produce an error. 23 24 ## Examples 25 26 ``` 27 > tonumber(1) 28 1 29 > tonumber("1") 30 1 31 > tonumber("no") 32 Error: Invalid function argument 33 34 Invalid value for "v" parameter: cannot convert "no" to number: string must be 35 a decimal representation of a number. 36 ```