Codebase list golang-github-vbauerster-mpb / 779ef26
math.Round Vladimir Bauer 8 years ago
1 changed file(s) with 4 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
269269 }
270270
271271 var str string
272 timeRemaining := time.Duration(float64(st.Total-st.Current) * s.Value())
272 timeRemaining := time.Duration(st.Total-st.Current) * time.Duration(math.Round(s.Value()))
273273 hours := int64((timeRemaining / time.Hour) % 60)
274274 minutes := int64((timeRemaining / time.Minute) % 60)
275275 seconds := int64((timeRemaining / time.Second) % 60)
344344 }
345345
346346 // CalcPercentage is a helper function, to calculate percentage.
347 func CalcPercentage(total, current, width int64) (perc int64) {
347 func CalcPercentage(total, current, width int64) int64 {
348348 if total <= 0 {
349349 return 0
350350 }
352352 current = total
353353 }
354354
355 num := float64(width) * float64(current) / float64(total)
356 ceil := math.Ceil(num)
357 diff := ceil - num
358 // num = 2.34 will return 2
359 // num = 2.44 will return 3
360 if math.Max(diff, 0.6) == diff {
361 return int64(num)
362 }
363 return int64(ceil)
355 p := float64(width) * float64(current) / float64(total)
356 return int64(math.Round(p))
364357 }
365358
366359 // SpeedNoUnit returns raw I/O operation speed decorator.