go 数学运算

最近发现一个问题

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章