Skip to content

[@internationalized/number] 0 decimals treated as zero when parsing with exceptZero #8199

Closed
@AndrewLeedham

Description

@AndrewLeedham

Provide a general summary of the issue here

When parsing numbers I would expect the exceptZero option to match the formatting behavior of Intl.NumberFormat but there seems to be a regression where it is seeing decimals that start with 0 as zero.

🤔 Expected Behavior?

new NumberParser('en-US', {style: 'percent', signDisplay: 'exceptZero', minimumFractionDigits: 2}).parse('+0.50%') should parse to 0.005 as the inverse new Intl.NumberFormat('en-US', {style: 'percent', signDisplay: 'exceptZero', minimumFractionDigits: 2}).format('0.005') gives "+0.50%"

😯 Current Behavior

new NumberParser('en-US', {style: 'percent', signDisplay: 'exceptZero', minimumFractionDigits: 2}).parse('+0.50%') gives NaN seemingly because it is treating 0.* as 0.

💁 Possible Solution

Still trying to figure out exactly how

works

🔦 Context

For now I am working around the issue with signDisplay: auto, but I would like to display + and - to make a number input have a fixed length, unless the value is exactly 0.

🖥️ Steps to Reproduce

Pull: https://github.com/AndrewLeedham/react-spectrum/tree/AL/number-repro then run yarn && yarn jest NumberParser

Version

@internationalized/[email protected]

What browsers are you seeing the problem on?

Firefox

If other, please specify.

No response

What operating system are you using?

Windows 11

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions