Bou*_*TAC 2 string format integer go
我有这个:
\nnewStr := fmt.Sprintf("new price: %d\xe2\x82\xac", newPrice)\nfmt.Println(newStr) // new price: %!d(string=500.00)\xe2\x82\xac\n// except I want: new price: 500,00\xe2\x82\xac\nRun Code Online (Sandbox Code Playgroud)\n如何删除字符串末尾的%!d(和 ,这样它就可以像这样)new price: 500,00\xe2\x82\xac
我可以使用一种格式,strings.Replace但我认为这不是一个好的答案。
我的newPrice是一个浮子。
我很确定这已经被问过,但很难用谷歌搜索这类事情。
\n问题是您%d在调用中使用整数值fmt.Sprintf(),但传递浮点值 (500,00)。
尝试这个:
\nnewStr := fmt.Sprintf("new price: %f\xe2\x82\xac", newPrice)\nfmt.Println(newStr) \nRun Code Online (Sandbox Code Playgroud)\n