最近发现一个问题
go在进行数学运算的时候会有问题。排查了好久。发现在做出发的时候 整数/整数。出来的还是乡下取整的整数, 先调整如下,做浮点数运算
var wg sync.WaitGroup goroutineDoCount := 20 //每个协程处理条数 fmt.Println(count / goroutineDoCount) fmt.Println(float64(count / goroutineDoCount)) fmt.Println(float64(count) / float64(goroutineDoCount)) goroutineCount := math.Ceil(float64(count / goroutineDoCount)) //协程数量 fmt.Println(goroutineCount) fmt.Println(math.Ceil(float64(count) / float64(goroutineDoCount))) base.InfoWithInterface("goroutineCount", goroutineCount) x := 1.1 fmt.Println(math.Ceil(x)) // 2 fmt.Println(math.Floor(x)) // 1