Adding dep files and dependencies.
This commit is contained in:
parent
45f9efa578
commit
b341c0a0e4
539 changed files with 313111 additions and 0 deletions
38
vendor/github.com/montanaflynn/stats/round.go
generated
vendored
Normal file
38
vendor/github.com/montanaflynn/stats/round.go
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
package stats
|
||||
|
||||
import "math"
|
||||
|
||||
// Round a float to a specific decimal place or precision
|
||||
func Round(input float64, places int) (rounded float64, err error) {
|
||||
|
||||
// If the float is not a number
|
||||
if math.IsNaN(input) {
|
||||
return math.NaN(), NaNErr
|
||||
}
|
||||
|
||||
// Find out the actual sign and correct the input for later
|
||||
sign := 1.0
|
||||
if input < 0 {
|
||||
sign = -1
|
||||
input *= -1
|
||||
}
|
||||
|
||||
// Use the places arg to get the amount of precision wanted
|
||||
precision := math.Pow(10, float64(places))
|
||||
|
||||
// Find the decimal place we are looking to round
|
||||
digit := input * precision
|
||||
|
||||
// Get the actual decimal number as a fraction to be compared
|
||||
_, decimal := math.Modf(digit)
|
||||
|
||||
// If the decimal is less than .5 we round down otherwise up
|
||||
if decimal >= 0.5 {
|
||||
rounded = math.Ceil(digit)
|
||||
} else {
|
||||
rounded = math.Floor(digit)
|
||||
}
|
||||
|
||||
// Finally we do the math to actually create a rounded number
|
||||
return rounded / precision * sign, nil
|
||||
}
|
Reference in a new issue