ngx-currency icon indicating copy to clipboard operation
ngx-currency copied to clipboard

Incorrect value using angular form builder

Open devfelipereis opened this issue 4 years ago • 5 comments

Example:

this.form = this.formBuilder.group({
      value: [4500, [Validators.required]],
});

Should return: R$ 45,00 It's returning: R$ 4.500,00

My configs:

export const customCurrencyMaskConfig = {
  align: "left",
  allowNegative: true,
  allowZero: true,
  decimal: ",",
  precision: 2,
  prefix: "R$ ",
  suffix: "",
  thousands: ".",
  nullable: true,
  min: null,
  max: null,
  inputMode: CurrencyMaskInputMode.FINANCIAL,
};

Am I missing something? Thank you.

devfelipereis avatar Jul 29 '20 00:07 devfelipereis

To return R$ 45,00 , you must inform 45.0 right? 4500 = 4.500,00

the component returned the correct value

LucasLopesr avatar Jul 29 '20 01:07 LucasLopesr

@LucasLopesr I was thinking that it was wrong because I'm using inputMode = CurrencyMaskInputMode.FINANCIAL If I type 4500 it will be R$ 45,00. So If I populate the input with 4500 via form buider or patchValue, it also should be R$ 45,00 and not R$ 4.500,00.

For now I'm passing 45.0 and it's working but using FINANCIAL I think that I should pass 4500.

What do you think?

devfelipereis avatar Jul 29 '20 10:07 devfelipereis

I think you should look at how the data is saved, when saving to a database it will not save 4500 to represent 45.0, this will generate a lot of inconsistency.

The input must format the user's input: 4500 -> 45,00 when sending this value somewhere or saving it should go like: 45.0 and will be loaded into the input as 45.0 and will display 45,00

I don't know if I managed to express myself well

LucasLopesr avatar Jul 29 '20 11:07 LucasLopesr

Yeah, I did understand. The issue is that my entire database monetary values are integers. So in my database I do save 4500 for R$ 45,00.

I think that some projects also save integers for monetary values and maybe this lib should have an option to accept integers when using FINANCIAL type.

Thank you!

devfelipereis avatar Jul 29 '20 12:07 devfelipereis

I too would like to see an integers option. As my data stored for monetary values are stored in whole pence (integers) - Alot of merchant and payment platforms work in integers to avoid rounding errors.

In my example

<input class="input input-price" currencyMask [(ngModel)]="value.price" [options]="{ prefix: '£ ', thousands: '.', decimal: '.', allowNegative: false }"" >

value.price = 650 displays = £650.00 Form Value = 650

type into input = 650 displays = £6.50 Form Value = 650

rmalcomber avatar Sep 13 '20 14:09 rmalcomber