Bug 33028: (follow-up) Add unformat_price js function

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-06-27 16:22:36 +01:00 committed by Tomas Cohen Arazi
parent 0199f5fbbb
commit 31cbd5ce94
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -32,5 +32,17 @@
var re = '\\d(?=(\\d{' + 3 + '})+' + '\\D' + ')', value = this.toFixed(decimal_digits); var re = '\\d(?=(\\d{' + 3 + '})+' + '\\D' + ')', value = this.toFixed(decimal_digits);
return value.replace('.', decimal_point).replace(new RegExp(re, 'g'), '$&' + thousands_sep); 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);
}
</script> </script>
<!-- / format-price.inc --> <!-- / format-price.inc -->