Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect value using angular form builder #109

Open
devfelipereis opened this issue Jul 29, 2020 · 5 comments
Open

Incorrect value using angular form builder #109

devfelipereis opened this issue Jul 29, 2020 · 5 comments

Comments

@devfelipereis
Copy link

devfelipereis commented Jul 29, 2020

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.

@LucasLopesr
Copy link
Contributor

LucasLopesr commented Jul 29, 2020

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

the component returned the correct value

@devfelipereis
Copy link
Author

devfelipereis commented Jul 29, 2020

@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?

@LucasLopesr
Copy link
Contributor

LucasLopesr commented Jul 29, 2020

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

@devfelipereis
Copy link
Author

devfelipereis commented Jul 29, 2020

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!

@rmalcomber
Copy link

rmalcomber commented Sep 13, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants