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