hugo/docs/content/en/functions/cast/ToInt.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1.1 KiB

title description keywords action aliases
cast.ToInt Converts a value to a decimal integer (base 10).
aliases related returnType signatures
int
functions/cast/ToFloat
functions/cast/ToString
int
cast/ToInt INPUT
/functions/int

With a decimal (base 10) input:

{{ int 11 }} → 11 (int)
{{ int "11" }} → 11 (int)

{{ int 11.1 }} → 11 (int)
{{ int 11.9 }} → 11 (int)

With a binary (base 2) input:

{{ int 0b11 }} → 3 (int)
{{ int "0b11" }} → 3 (int)

With an octal (base 8) input (use either notation):

{{ int 011 }} → 9 (int)
{{ int "011" }} → 9 (int)

{{ int 0o11 }} → 9 (int)
{{ int "0o11" }} → 9 (int)

With a hexadecimal (base 16) input:

{{ int 0x11 }} → 17 (int)
{{ int "0x11" }} → 17 (int)

{{% note %}} Values with a leading zero are octal (base 8). When casting a string representation of a decimal (base 10) number, remove leading zeros:

{{ strings/TrimLeft "0" "0011" | int }} → 11 {{% /note %}}