Standard library / strconv
strconv.AppendFloat()
Appends floating-point value with the FormatFloat format, precision and bitSize to dst. Returns the expanded slice; retain it even if the initial destination has enough capacity. Expected stdout: 'v=1.25\n'.
Formal Syntax & Structure
go syntaxgo
func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | []byte | Destination byte slice; existing prefix is preserved. |
| f | float64 | Floating-point value to encode. |
| fmt | byte | Formatting verb byte such as f, e or g. |
| prec | int | Verb-dependent output precision; -1 selects round-trip precision. |
| bitSize | int | Floating-point precision width, 32 or 64. |
Return Value
[]byte
Resulting byte slice, including original prefix.
Working Example
Example Snippetgo
package main
import ( "fmt" "strconv")
func main() { b := []byte("v=") b = strconv.AppendFloat(b, 1.25, 'f', 2, 64) fmt.Println(string(b))}