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) []byte

Parameters & Attributes

NameTypeDescription
dst[]byteDestination byte slice; existing prefix is preserved.
ffloat64Floating-point value to encode.
fmtbyteFormatting verb byte such as f, e or g.
precintVerb-dependent output precision; -1 selects round-trip precision.
bitSizeintFloating-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))}
Go Reference