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

@formatjs/intl-numberformat/polyfill: roundingIncrement seems to be a no-op #4359

Closed
udeyrishi opened this issue Feb 22, 2024 · 3 comments
Closed

Comments

@udeyrishi
Copy link

udeyrishi commented Feb 22, 2024

Which package?

@formatjs/intl-numberformat; specifically, the polyfill @formatjs/intl-numberformat/polyfill.

Describe the bug

I'm using formatjs in react-native, and due to the poor Intl support in hermes, using the intl-numberformat polyfill. It seems like the roundingIncrement property does not do anything.

To Reproduce

Reproducible Steps/Repo

I'm sure there's a non react-native way to reproduce this, but this is the leanest RN approach that I have:

  1. Create a new react native app, npx create-react-native-app intl-demo
  2. Add the dependencies via:
yarn add @formatjs/intl-datetimeformat @formatjs/intl-displaynames @formatjs/intl-getcanonicallocales @formatjs/intl-listformat @formatjs/intl-locale @formatjs/intl-pluralrules @formatjs/intl-relativetimeformat @formatjs/intl-segmenter @formatjs/intl-numberformat
  1. Import all the polyfills in the generated react-native App.js:
import "@formatjs/intl-locale/polyfill";
import "@formatjs/intl-pluralrules/polyfill";
import "@formatjs/intl-pluralrules/locale-data/en";
import "@formatjs/intl-datetimeformat/polyfill";
import "@formatjs/intl-datetimeformat/locale-data/en";
import "@formatjs/intl-datetimeformat/add-all-tz";
import "@formatjs/intl-relativetimeformat/polyfill";
import "@formatjs/intl-relativetimeformat/locale-data/en";
import "@formatjs/intl-displaynames/polyfill";
import "@formatjs/intl-displaynames/locale-data/en";
import "@formatjs/intl-listformat/polyfill";
import "@formatjs/intl-listformat/locale-data/en";
import "@formatjs/intl-segmenter/polyfill";
import "@formatjs/intl-numberformat/polyfill";
import "@formatjs/intl-numberformat/locale-data/en";
  1. console.log the output of this JS while running the app in an iOS simulator/Android emulator:
const formatted = new Intl.NumberFormat("en-CA", {
    roundingIncrement: 5,
    roundingMode: "floor",
    maximumFractionDigits: 0,
    minimumFractionDigits: 0,
  }).format(27.07);
  1. It'll output 27.07, instead of the expected 25
  2. On a semi-related note, removing the maximumFractionDigits and minimumFractionDigits properties altogether gives an error:

RangeError: With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal

Expected behavior

  • The number is correctly rounded
  • No error if the optional properties are removed.

Smartphone (please complete the following information):

  • Device: iPhone SE, iOS Simulator, Android emulator
  • OS: iOS 17.2, iOS 17.2.1, Android 14 (API 34)
  • package.json dump:
"@formatjs/intl-datetimeformat": "^6.12.2",
"@formatjs/intl-displaynames": "^6.6.6",
"@formatjs/intl-getcanonicallocales": "^2.3.0",
"@formatjs/intl-listformat": "^7.5.5",
"@formatjs/intl-locale": "^3.4.5",
"@formatjs/intl-numberformat": "^8.10.0",
"@formatjs/intl-pluralrules": "^5.2.12",
"@formatjs/intl-relativetimeformat": "^11.2.12",
"@formatjs/intl-segmenter": "^11.5.5",
"expo": "~50.0.7",
"expo-status-bar": "~1.11.1",
"react": "18.2.0",
"react-native": "0.73.4"
@udeyrishi udeyrishi added the bug label Feb 22, 2024
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Mar 24, 2024
@longlho
Copy link
Member

longlho commented Mar 27, 2024

do u have a codesandbox?

@github-actions github-actions bot removed the Stale label Mar 28, 2024
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Apr 27, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants