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

Format issue with average #546

Closed
Isha-Sharma opened this issue May 21, 2020 · 8 comments
Closed

Format issue with average #546

Isha-Sharma opened this issue May 21, 2020 · 8 comments

Comments

@Isha-Sharma
Copy link

Input: 999999
Format: {average: true}
Output: 1000k
Expected Output: 1m

Likewise, it's happening for all the corner cases.

Appreciate if someone could help me with this.

@BenjaminVanRyseghem
Copy link
Owner

@all-contributors please add @Isha-Sharma for bug

@allcontributors
Copy link
Contributor

@BenjaminVanRyseghem

I've put up a pull request to add @Isha-Sharma! 🎉

@BenjaminVanRyseghem
Copy link
Owner

Fixed in develop

@Isha-Sharma
Copy link
Author

Thanks @BenjaminVanRyseghem for the prompt response :)

@BenjaminVanRyseghem
Copy link
Owner

in numbro 2.3.0

@BenjaminVanRyseghem
Copy link
Owner

I changed a bit the interface to prevent losing a feature.

Often, when formatting currency, it's convenient to have more info, hence formatting 999 999 -> 1000k. On the other hand, when formatting numbers (as the number of attendants to an event), such precision is often useless, and we would prefer 999 999 -> 1m.

To allow such a behavior, I introduced lowPrecision: Boolean with the following behavior:

  • when true, it will always format as 1m
  • when false, it will always format as 1000k
  • when undefined, it will be true when formatting currency, false otherwise

@hafezdivandari
Copy link

hafezdivandari commented Jul 4, 2020

@BenjaminVanRyseghem

  • when true, it will always format as 1m
  • when false, it will always format as 1000k
  • when undefined, it will be true when formatting currency, false otherwise

But when lowPrecision is undefined, it will be false when formatting currency, true otherwise

numbro(999999).format({average:true, lowPrecision: false}); // "1000k"
numbro(999999).format({average:true, lowPrecision: true});  // "1m"
numbro(999999).format({average:true});                      // "1m"
numbro(999999).format({average:true, output: 'currency'});  // "$1000k"

@sammarks
Copy link

I think this was a breaking change; I get format errors now whenever using formatCurrency() without specifying average. It seems it injects lowPrecision in there regardless of if average is currently being used or not.

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

4 participants