summaryrefslogtreecommitdiff
path: root/round.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-05-21 18:30:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-05-21 18:30:07 +0200
commitdb72567ed07dd958157ba0aee5c157e688deadd6 (patch)
tree7babd3cdc84e9902e3628c3a042bdff7f8e4c7f7 /round.go
parentd6e30494ed753c634a702acb2174a0550bbb6342 (diff)
Expose n
Diffstat (limited to 'round.go')
-rw-r--r--round.go8
1 files changed, 2 insertions, 6 deletions
diff --git a/round.go b/round.go
index 89725f2..d1c625e 100644
--- a/round.go
+++ b/round.go
@@ -6,13 +6,9 @@ import "math"
// q = \sgn(y) \left\lfloor \left| y \right| + 0.5 \right\rfloor
// = -\sgn(y) \left\lceil -\left| y \right| - 0.5 \right\rceil
-func round(v float64, places int) float64 {
+// 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)
}
-
-// Round a float value to 2 decimal places
-func Round(v float64) float64 {
- return round(v, 2)
-}