diff options
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]) |
