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

Fix display of very small percentage values. #21368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dennisoelkers
Copy link
Member

Note: This needs a backport to 6.0 & 6.1.

Description

Motivation and Context

This PR is fixing an issue where very small values are displayed as NaN% in aggregation widgets. This is related to a bug in the underlying library used for formatting numbers. Due to this library being abandoned, this PR is starting to implement an abstraction layer that utilizes the Intl API to format numbers.

Replacing all previous usages of numeral with it is too much for a bugfix PR that is supposed to be backported, but will be handled through follow-up PRs instead.

Fixes #21185.

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@dennisoelkers dennisoelkers marked this pull request as ready for review January 16, 2025 11:11
} as const;

export const formatNumber = (num: number, options: Options = {}) => new Intl.NumberFormat(undefined, { ...defaultOptions, ...options }).format(num);
export const formatPercentage = (num: number, options: Options = {}) => new Intl.NumberFormat(undefined, { ...defaultPercentageOptions, ...options }).format(num);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it make sense to put minimumFractionDigits: 2 as a default option? Or do we have different use cases?

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

Successfully merging this pull request may close these issues.

Very small percentage value incorrectly displayed as NaN% in aggregation
2 participants