3
I am having a hard time with a problem that I believe is very easy to solve, but I am struggling hard enough to reach such a solution. I have a simple input that format using the brmasker library (ionic3). The user enters a value and it is formatted in real time, so far so good. In my console.log I receive the format value properly in string format. But when it comes to going up to the database this value, I need it to be NUMBER, so I use a parseFloat() as I always have, but I can’t get the values correctly, it doesn’t consider the two decimal places after the comma and if I try to use a parseFloat(2) it returns me a string, not a number.
Follow my code and some prints explaining the problem.
<ion-item>
<ion-input type="text" [(ngModel)]="valorMeta"
[brmasker]="{money: true, thousand: '.', decimalCaracter: ',', decimal: '2'}">
</ion-input>
</ion-item>
No ts is something simple like:
console.log(this.valorMeta);
console.log(parseFloat(this.valorMeta));
The images:
I managed to get a slightly better result, using this condition: console.log(parseFloat(this.valorMeta.replace(',', '.'))); But it still doesn’t return as expected, when the numbers are too high, it still doesn’t catch correctly.
– Diego Estacho