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) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| format | string | Format string containing literal text and formatting or scanning directives. |
| a | ...any | Values 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))}