Standard library / fmt

fmt.Sprintf()

Returns a formatted string; useful for constructing a message before storing or sending it. Does not return a write error. Expected stdout: 'total: 2.50\n'.

Formal Syntax & Structure

go syntaxgo
func Sprintf(format string, a ...any) string

Parameters & Attributes

NameTypeDescription
formatstringFormat string containing literal text and formatting or scanning directives.
a...anyValues consumed by formatting; may be empty.

Return Value

string

Formatted text.

Working Example

Example Snippetgo
package main
import (  "fmt")
func main() {  fmt.Println(fmt.Sprintf("%s: %.2f", "total", 2.5))}
Go Reference