From ded941158042d8b09164a9f8049fd7108b715680 Mon Sep 17 00:00:00 2001 From: Eric Ponce Date: Sun, 26 Aug 2018 19:32:07 +0200 Subject: [PATCH] math: add Round and RoundToEven examples Change-Id: Ibef5f96ea588d17eac1c96ee3992e01943ba0fef Reviewed-on: https://go-review.googlesource.com/131496 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/math/example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/math/example_test.go b/src/math/example_test.go index a1f764bcda..25d6975903 100644 --- a/src/math/example_test.go +++ b/src/math/example_test.go @@ -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 +} -- 2.50.0