1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-07 20:17:05 +00:00

new /x/jsonx and /x/mathx util sub-packages

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-11-06 20:25:25 +02:00
parent 485395190b
commit 51fc2f35ca
9 changed files with 567 additions and 0 deletions

28
x/mathx/round.go Normal file
View File

@@ -0,0 +1,28 @@
package mathx
import "math"
// Round rounds the "input" on "roundOn" (e.g. 0.5) on "places" digits.
func Round(input float64, roundOn float64, places float64) float64 {
pow := math.Pow(10, places)
digit := pow * input
_, div := math.Modf(digit)
if div >= roundOn {
return math.Ceil(digit) / pow
}
return math.Floor(digit) / pow
}
// RoundUp rounds up the "input" up to "places" digits.
func RoundUp(input float64, places float64) float64 {
pow := math.Pow(10, places)
return math.Ceil(pow*input) / pow
}
// RoundDown rounds down the "input" up to "places" digits.
func RoundDown(input float64, places float64) float64 {
pow := math.Pow(10, places)
return math.Floor(pow*input) / pow
}