Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'

This commit is contained in:
Bjørn Erik Pedersen
2023-10-20 09:43:56 +02:00
298 changed files with 4568 additions and 1991 deletions

View File

@@ -0,0 +1,53 @@
---
title: cast.ToFloat
linkTitle: float
description: Casts a value to a decimal (base 10) floating point value.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [float]
returnType: float64
signatures: [cast.ToFloat INPUT]
relatedFunctions:
- cast.ToFloat
- cast.ToInt
- cast.ToString
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)
```

View File

@@ -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 %}}

View File

@@ -0,0 +1,56 @@
---
title: cast.ToString
linkTitle: string
description: Cast a value to a string.
categories: [functions]
keywords: []
menu:
docs:
parent: functions
function:
aliases: [string]
returnType: string
signatures: [cast.ToString INPUT]
relatedFunctions:
- cast.ToFloat
- cast.ToInt
- cast.ToString
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)
```