mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
This commit is contained in:
48
docs/content/en/functions/cast/ToFloat.md
Normal file
48
docs/content/en/functions/cast/ToFloat.md
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
title: cast.ToFloat
|
||||
description: Converts a value to a decimal floating-point number (base 10).
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [float]
|
||||
related:
|
||||
- functions/cast/ToInt
|
||||
- functions/cast/ToString
|
||||
returnType: float64
|
||||
signatures: [cast.ToFloat INPUT]
|
||||
aliases: [/functions/float]
|
||||
---
|
||||
|
||||
With a decimal (base 10) input:
|
||||
|
||||
```go-html-template
|
||||
{{ float 11 }} → 11 (float64)
|
||||
{{ float "11" }} → 11 (float64)
|
||||
|
||||
{{ float 11.1 }} → 11.1 (float64)
|
||||
{{ float "11.1" }} → 11.1 (float64)
|
||||
|
||||
{{ float 11.9 }} → 11.9 (float64)
|
||||
{{ float "11.9" }} → 11.9 (float64)
|
||||
```
|
||||
|
||||
With a binary (base 2) input:
|
||||
|
||||
```go-html-template
|
||||
{{ float 0b11 }} → 3 (float64)
|
||||
```
|
||||
|
||||
With an octal (base 8) input (use either notation):
|
||||
|
||||
```go-html-template
|
||||
{{ float 011 }} → 9 (float64)
|
||||
{{ float "011" }} → 11 (float64)
|
||||
|
||||
{{ float 0o11 }} → 9 (float64)
|
||||
```
|
||||
|
||||
With a hexadecimal (base 16) input:
|
||||
|
||||
```go-html-template
|
||||
{{ float 0x11 }} → 17 (float64)
|
||||
```
|
53
docs/content/en/functions/cast/ToInt.md
Normal file
53
docs/content/en/functions/cast/ToInt.md
Normal file
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: cast.ToInt
|
||||
description: Converts a value to a decimal integer (base 10).
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [int]
|
||||
related:
|
||||
- functions/cast/ToFloat
|
||||
- functions/cast/ToString
|
||||
returnType: int
|
||||
signatures: [cast/ToInt INPUT]
|
||||
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 %}}
|
51
docs/content/en/functions/cast/ToString.md
Normal file
51
docs/content/en/functions/cast/ToString.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
title: cast.ToString
|
||||
description: Converts a value to a string.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [string]
|
||||
related:
|
||||
- functions/cast/ToFloat
|
||||
- functions/cast/ToInt
|
||||
returnType: string
|
||||
signatures: [cast.ToString INPUT]
|
||||
aliases: [/functions/string]
|
||||
---
|
||||
|
||||
With a decimal (base 10) input:
|
||||
|
||||
```go-html-template
|
||||
{{ string 11 }} → 11 (string)
|
||||
{{ string "11" }} → 11 (string)
|
||||
|
||||
{{ string 11.1 }} → 11.1 (string)
|
||||
{{ string "11.1" }} → 11.1 (string)
|
||||
|
||||
{{ string 11.9 }} → 11.9 (string)
|
||||
{{ string "11.9" }} → 11.9 (string)
|
||||
```
|
||||
|
||||
With a binary (base 2) input:
|
||||
|
||||
```go-html-template
|
||||
{{ string 0b11 }} → 3 (string)
|
||||
{{ string "0b11" }} → 0b11 (string)
|
||||
```
|
||||
|
||||
With an octal (base 8) input (use either notation):
|
||||
|
||||
```go-html-template
|
||||
{{ string 011 }} → 9 (string)
|
||||
{{ string "011" }} → 011 (string)
|
||||
|
||||
{{ string 0o11 }} → 9 (string)
|
||||
{{ string "0o11" }} → 0o11 (string)
|
||||
```
|
||||
|
||||
With a hexadecimal (base 16) input:
|
||||
|
||||
```go-html-template
|
||||
{{ string 0x11 }} → 17 (string)
|
||||
{{ string "0x11" }} → 0x11 (string)
|
||||
```
|
12
docs/content/en/functions/cast/_index.md
Normal file
12
docs/content/en/functions/cast/_index.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
title: Cast functions
|
||||
linkTitle: cast
|
||||
description: Template functions to cast a value from one data type to another.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
---
|
||||
|
||||
Use these functions to cast a value from one data type to another.
|
Reference in New Issue
Block a user