From the source below, I want to get float type result 33.33
.
If use fmt.Sprintf("%.2f", v)
can work well. But want to get the result in the floatTest
function. How to do?
func main() {
v := floatTest(30, 90)
fmt.Println(v)
// 33.33333333333333
vv := fmt.Sprintf("%.2f", v)
fmt.Println(vv)
// 33.33
}
func floatTest(count float64, total float64) float64 {
return (count / total * 100)
}