diff options
| author | horus_arch | 2018-02-04 20:54:58 +0100 |
|---|---|---|
| committer | horus_arch | 2018-02-04 20:54:58 +0100 |
| commit | 4f7a9316da8e19fa9466ee377148c7d07bf39fd9 (patch) | |
| tree | 7c4fb5b35ea107d7379b4c7a601aa9a7d9d184d5 /sanitize_price.go | |
| parent | fe12a1d41d74ac55dc3c1b27821375541ee5f2b2 (diff) | |
| download | alkobote-4f7a9316da8e19fa9466ee377148c7d07bf39fd9.tar.gz | |
Data from all shops are now saved in a data structure.
Diffstat (limited to 'sanitize_price.go')
| -rw-r--r-- | sanitize_price.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sanitize_price.go b/sanitize_price.go index 8b9443f..2052842 100644 --- a/sanitize_price.go +++ b/sanitize_price.go @@ -7,6 +7,10 @@ import ( ) func sanitize_price(price string) (int, error) { + if "" == price { + return 0, errors.New("Empty string") + } + multiply_by_10 := false multiply_by_100 := true @@ -24,6 +28,12 @@ func sanitize_price(price string) (int, error) { price = strings.TrimSuffix(strings.ToLower(price), "euro") price = strings.TrimSpace(price) + if len(price) < 2 { + price = "0" + price + } else if len(price) < 3 { + price = "00" + price + } + c := string(price[len(price)-2:]) c = string(c[0:1]) |
