1
0
mirror of https://github.com/golang/go synced 2024-11-23 13:40:04 -07:00

math: add Round and RoundToEven examples

Change-Id: Ibef5f96ea588d17eac1c96ee3992e01943ba0fef
Reviewed-on: https://go-review.googlesource.com/131496
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Eric Ponce 2018-08-26 19:32:07 +02:00 committed by Ian Lance Taylor
parent 61318d7ffe
commit ded9411580

View File

@ -113,3 +113,25 @@ func ExamplePow10() {
fmt.Printf("%.1f", c)
// Output: 100.0
}
func ExampleRound() {
p := math.Round(10.5)
fmt.Printf("%.1f\n", p)
n := math.Round(-10.5)
fmt.Printf("%.1f\n", n)
// Output:
// 11.0
// -11.0
}
func ExampleRoundToEven() {
u := math.RoundToEven(11.5)
fmt.Printf("%.1f\n", u)
d := math.RoundToEven(12.5)
fmt.Printf("%.1f\n", d)
// Output:
// 12.0
// 12.0
}