You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Test case 4 has been changed to expect -0, as this is a different value than 0 in JS. This is a gray area and a manual comparison could be added to convert results of -0 back to 0, if desired.
Test cases 6, 9 have been changed to reflect the proper expected value (default 2 figures after decimal point, proper rounding)
Test case 7 has been changed, as the number should still evaluate regardless of the sign display option
Test case 8 has been changed to be proper expected value
I have submitted a PR to amend test cases 2, 6, 7.
Provide a general summary of the issue here
When parsing numbers I would expect the
exceptZero
option to match the formatting behavior ofIntl.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 to0.005
as the inversenew 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%')
givesNaN
seemingly because it is treating0.*
as0
.💁 Possible Solution
Still trying to figure out exactly how
react-spectrum/packages/@internationalized/number/src/NumberParser.ts
Line 119 in cea861e
🔦 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
The text was updated successfully, but these errors were encountered: