diff options
| author | horus_arch | 2018-02-04 20:01:53 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-04 20:01:53 +0100 |
| commit | c2ffa908a41ae8b4f8cd9471e2ecd927ece94631 (patch) | |
| tree | fc2a5cf179188ec78f189dcc13e956202ff76dae | |
| parent | a8a23a6cb3f20a3e1813f191727bcdb9c6884548 (diff) | |
| download | alkobote-c2ffa908a41ae8b4f8cd9471e2ecd927ece94631.tar.gz | |
Bugfix in price sanitization.
| -rw-r--r-- | sanitize_price.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sanitize_price.go b/sanitize_price.go index 5be9e67..8b9443f 100644 --- a/sanitize_price.go +++ b/sanitize_price.go @@ -7,7 +7,8 @@ import ( ) func sanitize_price(price string) (int, error) { - multiply_by_100 := false + multiply_by_10 := false + multiply_by_100 := true price = strings.TrimSpace(price) @@ -17,6 +18,12 @@ func sanitize_price(price string) (int, error) { price = strings.TrimSuffix(price, "€") price = strings.TrimSpace(price) + price = strings.TrimSuffix(strings.ToLower(price), "eur") + price = strings.TrimSpace(price) + + price = strings.TrimSuffix(strings.ToLower(price), "euro") + price = strings.TrimSpace(price) + c := string(price[len(price)-2:]) c = string(c[0:1]) @@ -29,6 +36,7 @@ func sanitize_price(price string) (int, error) { } multiply_by_10 = true + multiply_by_100 = false } else if "." == c { if strings.Count(price, ".") > 1 { @@ -36,10 +44,11 @@ func sanitize_price(price string) (int, error) { } multiply_by_10 = true + multiply_by_100 = false } - c := string(price[len(price)-3:]) + c = string(price[len(price)-3:]) c = string(c[0:1]) /* @@ -50,14 +59,16 @@ func sanitize_price(price string) (int, error) { return 0, errors.New("Invalid format") } - multiply_by_100 = true + multiply_by_10 = false + multiply_by_100 = false } else if "." == c { if strings.Count(price, ".") > 1 { return 0, errors.New("Invalid format") } - multiply_by_100 = true + multiply_by_10 = false + multiply_by_100 = false } |
