Enable displayable unit price for price with comma as decimal separator

Retrieve the current decimal separator used to display price (`I18n.toCurrency()`), and check if number is formatted with only if this is `,`. If so, remplace comma by point, to pass the check `!isNaN`, and format unit price
This commit is contained in:
Jean-Baptiste Bellet
2021-05-24 10:54:43 +02:00
parent 560f462f7b
commit d066f0b94d
2 changed files with 11 additions and 2 deletions

View File

@@ -0,0 +1,8 @@
angular.module("admin.utils").filter "unlocalizeCurrency", ()->
# Convert string to number using injected currency configuration.
(price) ->
# used decimal separator from currency configuration
decimal_separator = I18n.toCurrency(.1, {precision: 1, unit: ''}).substring(1,2)
if (decimal_separator == ",")
price = price.replace(",", ".")
return parseFloat(price)