fmt.Sprintf()

Sprintf formats according to a format specifier and returns the resulting string. That means anything we pass into the Sprintf function will return a string.

// formatting results into new variables
formatedFV := fmt.Sprintf("Future Value: %.2f $", futureValue)
formatedRFV := fmt.Sprintf("Future Value adjusted for Inflation: %.2f $", futureRealValue)

// output both values
fmt.Printf("%s\n%s", formatedFV, formatedRFV)

Last updated