Home > database >  golang how to remove %!d(string= in string
golang how to remove %!d(string= in string

Time:03-16

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.

Edit: for people downvoting, at least please provide a duplicate topic.

CodePudding user response:

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) 
  • Related