go get github.com/unixlinuxgeek/round
Example:
package main
import (
"fmt"
"math"
"github.com/unixlinuxgeek/round"
)
func main() {
ceil := round.Ceil(math.Pi)
fmt.Printf("ceil: %.2f\n", ceil)
rnd := round.Round(math.Pi)
fmt.Printf("round: %.2f\n", rnd)
fl := round.Floor(math.Pi)
fmt.Printf("floor: %.2f\n", fl)
}
Run tests:
go test -test.v
Example:
$ go test -test.v
=== RUN TestRound
round_test.go:10: Generate random float64 number(1-9): 8.704279
round_test.go:12: after round: 8.710
round_test.go:13: rand: 8.704
round_test.go:18: Test Round Passed!!!
--- PASS: TestRound (0.00s)
=== RUN TestCeil
round_test.go:24: Generate random float64 number(1-9): 4.019324
round_test.go:26: after ceil: 4.020000
round_test.go:27: rand: 4.019324
round_test.go:32: Test Ceil Passed!!!
--- PASS: TestCeil (0.00s)
=== RUN TestFloor
round_test.go:38: Generate random float64 number(1-9): 1.450042
round_test.go:40: after floor: 1.460000
round_test.go:41: rand: 1.450042
round_test.go:46: Test Floor Passed!!!
--- PASS: TestFloor (0.00s)
PASS
ok github.com/unixlinuxgeek/round 0.002s