Skip to content

[Amount] Improve formatting capabilities and fix edge cases #595

@ravisuhag

Description

@ravisuhag

Summary

Improvements to the Amount component to enhance formatting capabilities, fix edge cases, and follow component conventions.

Improvements

2. Add notation prop

No way to get compact formatting like $1.2M or $13K. Intl.NumberFormat supports notation: 'compact' natively. This is useful for dashboards and summary views.

3. Add narrowSymbol to currencyDisplay

Intl.NumberFormat supports 'narrowSymbol' (e.g., $ instead of US$ in non-US locales), but the currencyDisplay prop only allows 'symbol' | 'code' | 'name'.

4. Add signDisplay prop

Intl.NumberFormat supports signDisplay ('auto', 'always', 'exceptZero', 'never') for controlling +/- sign display — useful for showing gains/losses.

5. Memoize formatter instances

getCurrencyDecimals() and isValidCurrency() each create a new Intl.NumberFormat instance on every render. These should be memoized or combined into a single formatter creation.

6. Fix string slicing edge case for short strings

value.slice(0, -decimals) + '.' + value.slice(-decimals) breaks for strings shorter than the decimal count (e.g., value="5" with USD → ".5" instead of "0.05").

Moved to Cross-Cutting Issues

The following items have been moved to cross-cutting issues that address them across all components:

Metadata

Metadata

Assignees

No one assigned

    Labels

    componentIndividual component-level issuetriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions