Standard library / strconv
strconv.FormatFloat()
Formats a float with format byte (such as f, e, g, x), precision and bitSize 32 or 64. Precision -1 uses the shortest representation that round-trips for the chosen size; f precision gives decimal places. Expected stdout: '1.250\n'.
Formal Syntax & Structure
go syntaxgo
func FormatFloat(f float64, fmt byte, prec, bitSize int) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| 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
string
Encoded representation.
Working Example
Example Snippetgo
package main
import ( "fmt" "strconv")
func main() { fmt.Println(strconv.FormatFloat(1.25, 'f', 3, 64))}