-2
Hi, I was wondering if there’s something wrong with that function that won’t let me remove the semicolon from the string. What happens is that I have an input that when receiving the entered value it formats the typed text to the BRL standard
console.log(moneyMask(1579846));
saída:
15.798,46;
So far, so good but if I add more digits the output is like this:
console.log(moneyMask(15.798,4656));
saída:
15.798,46,56;
Here is the function code:
static moneyMask(value) {
let tmp = value + '';
tmp.replace(/[\D]+/g, '');
tmp = tmp.replace(/([0-9]{2})$/g, ',$1');
if (tmp.length > 6) {
tmp = tmp.replace(/([0-9]{3}),([0-9]{2}$)/g, '.$1,$2');
}
if (tmp.length > 9) {
tmp = tmp.replace(/([0-9]{3}).([0-9]{3}),([0-9]{2})$/g, '.$1.$2,$3');
}
return tmp;
}
Note that the tmp.replace(/[\D]+/g, '');
should clear the semicolon.
"dying to search" just 25 minutes after asking? https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83Quest
– Aurium
"just 25 minutes after asking" like I was looking after I asked the question '-' I spent the whole morning looking. If you’re not going to comment on something constructive, don’t comment on it
– Qattus