From fc83917d623228b09191f178062e59fad0722795 Mon Sep 17 00:00:00 2001 From: horus_arch Date: Sat, 17 Feb 2018 15:07:52 +0100 Subject: Adds crawler for whiskysite.nl. (crawler) --- crawler/utility.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'crawler/utility.go') 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 +} -- cgit v1.2.3