From 31cbd5ce946832234c8eb6b99729d781e75fd4bc Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 27 Jun 2023 16:22:36 +0100 Subject: [PATCH] Bug 33028: (follow-up) Add unformat_price js function Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../intranet-tmpl/prog/en/includes/format_price.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc index fd1d68112b..6790bc8d59 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc @@ -32,5 +32,17 @@ var re = '\\d(?=(\\d{' + 3 + '})+' + '\\D' + ')', value = this.toFixed(decimal_digits); return value.replace('.', decimal_point).replace(new RegExp(re, 'g'), '$&' + thousands_sep); } + String.prototype.unformat_price = function (params) { + params = params == undefined ? {} : params; + var thousands_sep = params.thousands_sep == undefined ? default_value.thousands_sep : params.thousands_sep, + decimal_point = params.decimal_point == undefined ? default_value.decimal_point : params.decimal_point, + //symbol = params.symbol == undefined ? '$' : params.symbol, // Not implemented yet + decimal_digits = params.decimal_digits == undefined ? default_value.decimal_digits : params.decimal_digits; + + let value = this.valueOf(); + value = value.replace(thousands_sep, '').replace(decimal_point, '.').replace(new RegExp('[^\\d.]', 'g'), ''); + return Number(value).toFixed(decimal_digits); + } + -- 2.39.5