Hey I am trying to write some code to handle the unformatting of EU and US numbers but I can not get a perfect solution.
For example I would like
1.222.222,89 to be 1222222.89 1,222,222.89 to be 1222222.89
I am using AG GRID and I am pasting numbers to the grid which ag grid is storing as strings.
what I have got so far but will not work with numbers with only a single ',' or '.'
let unformattedNumber = params.value as string;
unformattedNumber = unformattedNumber.replace("%", "");
unformattedNumber = unformattedNumber.replace(/ /g, "");
const lastCommaIndex = unformattedNumber.lastIndexOf(",");
const lastPeriodIndex = unformattedNumber.lastIndexOf(".");
if (lastCommaIndex > lastPeriodIndex) {
unformattedNumber = unformattedNumber.replace(/\./g, "");
unformattedNumber = unformattedNumber.replace(",", ".");
} else if (lastPeriodIndex > lastCommaIndex) {
unformattedNumber = unformattedNumber.replace(/,/g, "");
}
return parseFloat(unformattedNumber);