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

[Tooling] Improve numberStringFormatter helper to handle style:"percent" option #7399

Open
1 of 3 tasks
macandcheese opened this issue Jul 31, 2023 · 2 comments
Open
1 of 3 tasks
Labels
0 - new New issues that need assignment. Calcite (design) Issues logged by Calcite designers. enhancement Issues tied to a new feature or request. estimate - 8 Requires input from team, consider smaller steps. i18n-l10n issues dealing with internationalization/localization impact - p2 - want for an upcoming milestone User set priority impact status of p2 - want for an upcoming milestone p - low Issue is non core or affecting less that 10% of people using the library
Milestone

Comments

@macandcheese
Copy link
Contributor

macandcheese commented Jul 31, 2023

Check existing issues

Description

Currently, our localized number helper produces unexpected results when using the style: "percent" option.

Acceptance Criteria

I'd expect to get the same output as I would here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat

where when value=0.5,

return Intl.NumberFormat("en", {
  style: "percent",
}).format(value);

returns 50%

Using our helper and the following numberFormatOptions

numberFormatOptions = {
  locale: this.effectiveLocale,
  numberingSystem: this.numberingSystem,
  useGrouping: this.groupSeparator,
  style: "percent",
}; 

return numberStringFormatter.localize(value.toString());

the result is 0%.500%. If value=0.75, the result is 0%.700%500%

Relevant Info

cc @benelan

Which Component

No component

Example Use Case

No response

Priority impact

p3 - want for upcoming milestone

Calcite package

  • @esri/calcite-components
  • @esri/calcite-components-react

Esri team

Calcite (design)

@macandcheese macandcheese added enhancement Issues tied to a new feature or request. 0 - new New issues that need assignment. needs triage Planning workflow - pending design/dev review. labels Jul 31, 2023
@github-actions github-actions bot added Calcite (design) Issues logged by Calcite designers. p3 - want for upcoming milestone labels Jul 31, 2023
@annierm18 annierm18 added the i18n-l10n issues dealing with internationalization/localization label Aug 4, 2023
@benelan
Copy link
Member

benelan commented Aug 17, 2023

Based on the examples you gave this is likely a regression from #7159. It may be as easy as stripping non-numeric characters from the end of the value before handling the trailing zeros case.

@geospatialem geospatialem added impact - p2 - want for an upcoming milestone User set priority impact status of p2 - want for an upcoming milestone and removed p3 - want for upcoming milestone labels May 21, 2024
@geospatialem geospatialem added p - low Issue is non core or affecting less that 10% of people using the library estimate - 8 Requires input from team, consider smaller steps. and removed needs triage Planning workflow - pending design/dev review. labels May 28, 2024
@geospatialem geospatialem added this to the Freezer milestone Jun 4, 2024
@geospatialem
Copy link
Member

The above was added to the Freezer ❄️ with a lower priority and higher estimate.

Ben mentioned his comment above is not correct, and instead mentioned it shifts decimals and adding 0's in addition to styling. The number locale utils were designed specifically for user input, which is why they are so complicated.

However, WRT the above, if we ever need to localize a percentage from user input we can re-evaluate this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - new New issues that need assignment. Calcite (design) Issues logged by Calcite designers. enhancement Issues tied to a new feature or request. estimate - 8 Requires input from team, consider smaller steps. i18n-l10n issues dealing with internationalization/localization impact - p2 - want for an upcoming milestone User set priority impact status of p2 - want for an upcoming milestone p - low Issue is non core or affecting less that 10% of people using the library
Projects
None yet
Development

No branches or pull requests

4 participants