github.com/jbramsden/hugo@v0.47.1/docs/content/en/functions/int.md (about)

     1  ---
     2  title: int
     3  linktitle: int
     4  description: Creates an `int` from the argument passed into the function.
     5  godocref:
     6  date: 2017-02-01
     7  publishdate: 2017-02-01
     8  lastmod: 2017-02-01
     9  categories: [functions]
    10  menu:
    11    docs:
    12      parent: "functions"
    13  keywords: [strings,integers]
    14  signature: ["int INPUT"]
    15  workson: []
    16  hugoversion:
    17  relatedfuncs: []
    18  deprecated: false
    19  aliases: []
    20  ---
    21  
    22  Useful for turning strings into numbers.
    23  
    24  ```
    25  {{ int "123" }} → 123
    26  ```
    27  
    28  {{% note "Usage Note" %}}
    29  If the input string is supposed to represent a decimal number, and if it has
    30  leading 0's, then those 0's will have to be removed before passing the string
    31  to the `int` function, else that string will be tried to be parsed as an octal
    32  number representation.
    33  
    34  The [`strings.TrimLeft` function](/functions/strings.trimleft/) can be used for
    35  this purpose.
    36  
    37  ```
    38  {{ int ("0987" | strings.TrimLeft "0") }}
    39  {{ int ("00987" | strings.TrimLeft "0") }}
    40  ```
    41  
    42  **Explanation**
    43  
    44  The `int` function eventually calls the `ParseInt` function from the Go library
    45  `strconv`.
    46  
    47  From its [documentation](https://golang.org/pkg/strconv/#ParseInt):
    48  
    49  > the base is implied by the string's prefix: base 16 for "0x", base 8 for "0",
    50  > and base 10 otherwise.
    51  {{% /note %}}