diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-20 09:43:56 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-10-20 09:43:56 +0200 |
commit | e2dd4cd05fa96a08d49b3b198edf0ccf9a94970e (patch) | |
tree | 712334f7e7a657155706f556040575bea9b7757f /docs/content/en/functions/cast/ToInt.md | |
parent | fd381718101a35a5f5f92d5a05b3a0c36ef50db0 (diff) | |
parent | e509cac533600cf4fa8382c9cdab78ddd82db688 (diff) |
Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'
Diffstat (limited to 'docs/content/en/functions/cast/ToInt.md')
-rw-r--r-- | docs/content/en/functions/cast/ToInt.md | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/docs/content/en/functions/cast/ToInt.md b/docs/content/en/functions/cast/ToInt.md new file mode 100644 index 000000000..b4a37cb6c --- /dev/null +++ b/docs/content/en/functions/cast/ToInt.md @@ -0,0 +1,59 @@ +--- +title: cast.ToInt +linkTitle: int +description: Casts a value to a decimal (base 10) integer. +categories: [functions] +keywords: [] +menu: + docs: + parent: functions +function: + aliases: [int] + returnType: int + signatures: [cast.ToInt INPUT] +relatedFunctions: + - cast.ToFloat + - cast.ToInt + - cast.ToString +aliases: [/functions/int] +--- + +With a decimal (base 10) input: + +```go-html-template +{{ int 11 }} → 11 (int) +{{ int "11" }} → 11 (int) + +{{ int 11.1 }} → 11 (int) +{{ int 11.9 }} → 11 (int) +``` + +With a binary (base 2) input: + +```go-html-template +{{ int 0b11 }} → 3 (int) +{{ int "0b11" }} → 3 (int) +``` + +With an octal (base 8) input (use either notation): + +```go-html-template +{{ int 011 }} → 9 (int) +{{ int "011" }} → 9 (int) + +{{ int 0o11 }} → 9 (int) +{{ int "0o11" }} → 9 (int) +``` + +With a hexadecimal (base 16) input: + +```go-html-template +{{ 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 %}} |