summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--round.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/round.go b/round.go
index d1c625e..345f7b0 100644
--- a/round.go
+++ b/round.go
@@ -7,8 +7,8 @@ import "math"
// = -\sgn(y) \left\lceil -\left| y \right| - 0.5 \right\rceil
// Round a float value to n decimal places
-func Round(v float64, places int) float64 {
- scale := math.Pow(10, float64(places))
- abs := math.Abs(v*scale) + 0.5
- return math.Copysign(math.Floor(abs)/scale, v)
+func Round(v float64, n int) float64 {
+ pow := math.Pow(10, float64(n))
+ abs := math.Abs(v*pow) + 0.5
+ return math.Copysign(math.Floor(abs)/pow, v)
}