From ab6aa1e920b6df65de71d5c6a46e2543ddae5403 Mon Sep 17 00:00:00 2001 From: psam21 Date: Thu, 27 Nov 2025 10:32:09 +0530 Subject: [PATCH] Fix clipboard copy for fiat amounts and other numeric values (#7011) Co-authored-by: rockstardev <5191402+rockstardev@users.noreply.github.com> --- BTCPayServer/wwwroot/checkout/checkout.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/wwwroot/checkout/checkout.js b/BTCPayServer/wwwroot/checkout/checkout.js index 23480806b..921ade0ae 100644 --- a/BTCPayServer/wwwroot/checkout/checkout.js +++ b/BTCPayServer/wwwroot/checkout/checkout.js @@ -57,7 +57,27 @@ function updateLanguage(lang) { } function asNumber(val) { - return val && parseFloat(val.toString().replace(/\s/g, '')); // e.g. sats are formatted with spaces: 1 000 000 + if (!val) return null; + let str = val.toString(); + + // Remove leading non-numeric characters (e.g. currency symbols like $, €, £) + str = str.replace(/^[^\d-]+/, ''); + + // Detect decimal separator: the last occurrence of . or , is the decimal separator + // Everything before it is thousands separators + const lastComma = str.lastIndexOf(','); + const lastDot = str.lastIndexOf('.'); + + if (lastComma > lastDot) { + // European format: 91.121,60 - comma is decimal, dots/spaces are thousands + str = str.replace(/[\s.]/g, '').replace(',', '.'); + } else { + // US/UK format: 91,121.60 - dot is decimal, commas/spaces are thousands + str = str.replace(/[\s,]/g, ''); + } + + const num = parseFloat(str); + return isNaN(num) ? null : num; } Vue.use(VueI18next);