diff options
Diffstat (limited to 'crawler/utility.go')
| -rw-r--r-- | crawler/utility.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crawler/utility.go b/crawler/utility.go index 29f14d6..f588c22 100644 --- a/crawler/utility.go +++ b/crawler/utility.go @@ -2,6 +2,7 @@ package main import ( "errors" + "math" "regexp" "strconv" "strings" @@ -189,3 +190,16 @@ func get_base_price(e *colly.HTMLElement) (int, error) { return base_price, nil } + +/* + * Source: https://golang.org/src/math/floor.go?s=2165:2200#L104 + * Will use std lib with go version >= 1.10 + */ +func RoundToEven(x float64) float64 { + t := math.Trunc(x) + odd := math.Remainder(t, 2) != 0 + if d := math.Abs(x - t); d > 0.5 || (d == 0.5 && odd) { + return t + math.Copysign(1, x) + } + return t +} |
