| 1 |
--- |
| 2 |
title: cast.ToFloat |
| 3 |
description: Returns the given value converted to a decimal floating-point number (base 10). |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [float] |
| 9 |
returnType: float64 |
| 10 |
signatures: [cast.ToFloat INPUT] |
| 11 |
aliases: [/functions/float] |
| 12 |
--- |
| 13 |
|
| 14 |
With a decimal (base 10) input: |
| 15 |
|
| 16 |
```go-html-template |
| 17 |
{{ float 11 }} → 11 (float64) |
| 18 |
{{ float "11" }} → 11 (float64) |
| 19 |
|
| 20 |
{{ float 11.1 }} → 11.1 (float64) |
| 21 |
{{ float "11.1" }} → 11.1 (float64) |
| 22 |
|
| 23 |
{{ float 11.9 }} → 11.9 (float64) |
| 24 |
{{ float "11.9" }} → 11.9 (float64) |
| 25 |
``` |
| 26 |
|
| 27 |
With a binary (base 2) input: |
| 28 |
|
| 29 |
```go-html-template |
| 30 |
{{ float 0b11 }} → 3 (float64) |
| 31 |
``` |
| 32 |
|
| 33 |
With an octal (base 8) input (use either notation): |
| 34 |
|
| 35 |
```go-html-template |
| 36 |
{{ float 011 }} → 9 (float64) |
| 37 |
{{ float "011" }} → 11 (float64) |
| 38 |
|
| 39 |
{{ float 0o11 }} → 9 (float64) |
| 40 |
``` |
| 41 |
|
| 42 |
With a hexadecimal (base 16) input: |
| 43 |
|
| 44 |
```go-html-template |
| 45 |
{{ float 0x11 }} → 17 (float64) |
| 46 |
``` |