I'm working on a german local based currency input using ionic(Angular). I want to show something like this
But back end API accepts the value as a floating number.
Ex:- 56.00
what I have currently done is
<ion-input
#amount="ngModel"
name="AMOUNT"
[required]="true"
[min]="50"
[max]="20000000"
(focusout)="rollBackTransformAmount()"
(focusIn)="transformAmount()"
[ngModel]="formattedAmount"
(ngModelChange)="transfer.amount=$event; formattedAmount=$event"
placeholder="Amount">
</ion-input>
and in ts
transformAmount(){
if(!isNaN(this.formattedAmount)){
this.formattedAmount = this.currencyPipe.transform(this.formattedAmount, 'EUR', 'symbol', '1.2-2', 'de');
}
}
rollBackTransformAmount(){
// todo
// this is what I want to implement
// get the floating number equivalent for this.formattedValue
}
UPDATE - I was able to come up with some thing like follow
transformAmount(){
if(!isNaN(this.formattedAmount)){
this.formattedAmount = this.currencyPipe.transform(this.formattedAmount, 'EUR', 'symbol', '1.0-2', 'de');
} else {
this.unFormatCurrencyAmount();
this.formattedAmount = this.currencyPipe.transform(this.formattedAmount, 'EUR', 'symbol', '1.0-2', 'de');
}
}
rollBackTransformAmount(){
this.unFormatCurrencyAmount();
console.log(this.formattedAmount);
}
unFormatCurrencyAmount(){
if(this.formattedAmount){
// eslint-disable-next-line max-len
this.formattedAmount = this.formattedAmount.replace(getCurrencySymbol('EUR', 'narrow','de'),'').trim().replaceAll('.','').replace(',','.');
}
}
Is there any proper way to achieve this