Standard library / fmt

fmt.width-precision-flags

Width specifies minimum field width; precision is verb-dependent. - left-aligns, 0 zero-pads numbers, + requests a sign for numbers, space requests a leading space for nonnegative numbers, # selects alternate formatting. * takes width or precision from an int argument; indexed operands such as %[2]d select an argument. Expected stdout: '| 7|8 |00009|+2.0|1.50|8|\n'.

Formal Syntax & Structure

go syntaxgo
%[argument-index][flags][width][.precision]verb (schematic; actual index placement varies)

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  fmt.Printf("|%5d|%-5d|%05d|%+.1f|%.*f|%[2]d|\n", 7, 8, 9, 2.0, 2, 1.5)}
Go Reference