'golang how to remove %!d(string= in string
I have this:
newStr := fmt.Sprintf("new price: %d€", newPrice)
fmt.Println(newStr) // new price: %!d(string=500.00)€
// except I want: new price: 500,00€
How to remove the %!d( and the ) at the end of the string so it can be like this new price: 500,00€
I could use a format the strings.Replace but I don't think it's the good answer.
My newPrice is a float.
I'm pretty sure it as already been ask but it's hard to google those kind of things.
Solution 1:[1]
The problem is that you're using %d for an integer value in your call to fmt.Sprintf(), but passing a floating-point value (500,00).
Try this:
newStr := fmt.Sprintf("new price: %f€", newPrice)
fmt.Println(newStr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | m0j0 |
