2019-10-21 04:22:28 -04:00
|
|
|
---
|
2023-10-20 03:42:39 -04:00
|
|
|
title: cast.ToString
|
|
|
|
linkTitle: string
|
2023-05-22 10:43:12 -04:00
|
|
|
description: Cast a value to a string.
|
2019-10-21 04:22:28 -04:00
|
|
|
categories: [functions]
|
2023-10-20 03:42:39 -04:00
|
|
|
keywords: []
|
2019-10-21 04:22:28 -04:00
|
|
|
menu:
|
|
|
|
docs:
|
2023-05-22 10:43:12 -04:00
|
|
|
parent: functions
|
2023-10-20 03:42:39 -04:00
|
|
|
function:
|
|
|
|
aliases: [string]
|
|
|
|
returnType: string
|
|
|
|
signatures: [cast.ToString INPUT]
|
|
|
|
relatedFunctions:
|
|
|
|
- cast.ToFloat
|
|
|
|
- cast.ToInt
|
|
|
|
- cast.ToString
|
|
|
|
aliases: [/functions/string]
|
2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
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)
|
|
|
|
```
|