Handle more cases with decimal/thousands separator

- ',' or '.' can be used as decimal separator (defined in the application configuration)
 - Remove thousands separator if it's detected as so (use regexp to match)
This commit is contained in:
Jean-Baptiste Bellet
2021-06-07 16:53:20 +02:00
parent f73e5c74fb
commit 3ebba9502a
2 changed files with 40 additions and 3 deletions

View File

@@ -6,11 +6,15 @@ angular.module("admin.utils").filter "unlocalizeCurrency", ()->
# used decimal and thousands separators from currency configuration
decimal_separator = I18n.toCurrency(.1, {precision: 1, unit: ''}).substring(1,2)
thousands_separator = I18n.toCurrency(1000, {precision: 1, unit: ''}).substring(1,2)
# Replace comma used as a decimal separator and remplace by "."
if (price.match(/^[0-9]*(,{1})[0-9]{1,2}$/g))
price = price.replace(",", ".")
if (price.length > 4)
# remove configured thousands separator if price is greater than 999
# Remove configured thousands separator if it is actually a thousands separator
if (new RegExp("^([0-9]*(" + thousands_separator + "{1})[0-9]{3}[0-9\.,]*)*$", "g").test(price))
price = price.replaceAll(thousands_separator, '')
if (decimal_separator == ",")
price = price.replace(",", ".")