Fix clipboard copy for fiat amounts and other numeric values (#7011)

Co-authored-by: rockstardev <5191402+rockstardev@users.noreply.github.com>
This commit is contained in:
psam21
2025-11-27 10:32:09 +05:30
committed by GitHub
parent 03349b6ffe
commit ab6aa1e920

View File

@@ -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);