Skip to content

Commit

Permalink
math: add Round and RoundToEven examples
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
trico authored and ianlancetaylor committed Aug 28, 2018
1 parent 61318d7 commit ded9411
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/math/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ded9411

Please sign in to comment.