概要
小数点第2、第3...と四捨五入する方法。
floatからstring
sample.go
v := fmt.Sprintf("%.2f", 12.3456)
fmt.Println(v) // "12.35"
v = fmt.Sprintf("%.3f", 12.3456)
fmt.Println(v) // "12.346"
floatからfloat
sample.go
v := 12.3456
fmt.Println(math.Round(v*100) / 100) // 12.35
fmt.Println(math.Round(v*1000) / 1000) // 12.346