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

Decimal inserted despite mantissaLength: 0 #106

Closed
ericbenwa opened this issue Nov 15, 2022 · 8 comments
Closed

Decimal inserted despite mantissaLength: 0 #106

ericbenwa opened this issue Nov 15, 2022 · 8 comments

Comments

@ericbenwa
Copy link

Trying to display 400000 as $400,000.

However, the following,
print(400000.toCurrencyString(mantissaLength: 0, leadingSymbol: MoneySymbols.DOLLAR_SIGN, trailingSymbol: ''));
displays as $400,000., displaying a period after the value.

In a prior release, this wasn't happening (I just updated from 2.0.2)
How do I avoid the . from being displayed?
Or is this the expected behavior?

Flutter (Channel stable, 3.3.8)

Thank you!

@ericbenwa ericbenwa changed the title Decimal displays despite mantissaLength: 0 Decimal inserted despite mantissaLength: 0 Nov 15, 2022
@gomezjc
Copy link

gomezjc commented Nov 17, 2022

Hi Everyone, any solution for this? I have the same issue :(

@caseyryan
Copy link
Owner

caseyryan commented Nov 18, 2022

Hi!
I just checked it and it works correctly. Can you confirm you have this problem with the latest version 2.9.6? I fixed this the other day #105 and I believe it should also fix the problem you're talking about because I had completely rewritten the logic of that function from scratch

Now my check was like this:

print(
      400000.toCurrencyString(
        mantissaLength: 0,
        leadingSymbol: MoneySymbols.DOLLAR_SIGN,
        trailingSymbol: '',
      ),
    );

And the display is:

flutter: $400,000

@ericbenwa
Copy link
Author

When I run flutter pub upgrade it displays flutter_multi_formatter 2.9.6.
So I presume I've got latest... ?

My pubspec.yaml displays the package as flutter_multi_formatter: ^2.9.6.

Thoughts on what I'm screwing up?

@caseyryan
Copy link
Owner

When I run flutter pub upgrade it displays flutter_multi_formatter 2.9.6. So I presume I've got latest... ?

My pubspec.yaml displays the package as flutter_multi_formatter: ^2.9.6.

Thoughts on what I'm screwing up?

Have you tried it again after you did it? I'm sure there was a bug you described but not anymore

@ericbenwa
Copy link
Author

Yes. Was trying a few times not sure what I'm missing.
I may switch to the Intl package to resolve this.

I'm happy to continue troubleshooting this issue if you have other ideas, but also fine if closed as I think I'll be switching to the Intl package.

@caseyryan
Copy link
Owner

caseyryan commented Nov 22, 2022

I must have misunderstood the question when I first read it. You said you only have period at the end. But I thought you also have a zero after it. I'll check it again. I think I know what may cause it

@caseyryan
Copy link
Owner

caseyryan commented Nov 22, 2022

You're right. The problem was in this function

  ThousandSeparator thousandSeparator,
  int mantissaLength,
) {
  if (mantissaLength < 1) {
    return '';
  }
  if (thousandSeparator == ThousandSeparator.Comma) {
    return '.';
  }
  if (thousandSeparator == ThousandSeparator.Period ||
      thousandSeparator == ThousandSeparator.SpaceAndCommaMantissa) {
    return ',';
  }
  return '.';
}

It paid no mind to the mantissa length. Fixed in 2.9.7

@ericbenwa
Copy link
Author

Ah, thank you, thank you!

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