hermes: Intl.NumberFormat notation: compact is not working on 0.71.7
Bug Description
- I have run
gradle cleanand confirmed this bug does not occur with JSC
Hermes version: { “Bytecode Version”: 90, “Builtins Frozen”: false, “VM Experiments”: 0, “Build”: “Release”, “GC”: “hades (concurrent)”, “OSS Release Version”: “for RN 0.71.7”, “CommonJS Modules”: “None” }
React Native version (if any): 0.71.7" OS version (if any): 0.71.7" Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): all
Steps To Reproduce
- Use Intl.NumberFormat with large number and notation as compact
code example:
function formatCompactNumber(number) {
const formatter = Intl.NumberFormat("en", { notation: "compact" });
console.log(formatter.format(number));
}
// the comments are what should be logged
formatCompactNumber(-57); // -57
formatCompactNumber(999); // 999
formatCompactNumber(8_554); // 8.5K
formatCompactNumber(150_000); // 150K
formatCompactNumber(3_237_512); // 3.2M
formatCompactNumber(9_782_716_897); // 9.8B
formatCompactNumber(7_899_693_036_970); // 7.9T
// below is what we got:
/*
LOG -57
LOG 999
LOG 8,554
LOG 150,000
LOG 3,237,512
LOG 9,782,716,897
LOG 7,899,693,036,970
*/
The Expected Behavior
Expected:
formatCompactNumber(150_000); // 150K
formatCompactNumber(3_237_512); // 3.2M
formatCompactNumber(9_782_716_897); // 9.8B
formatCompactNumber(7_899_693_036_970); // 7.9T
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 8
- Comments: 20 (12 by maintainers)
Commits related to this issue
- Update Intl API documentation to include iOS support (#1042) Summary: As discussed in issue https://github.com/facebook/hermes/issues/1035, the documentation of the Intl APIs does not include the cur... — committed to facebook/hermes by jobpaardekooper a year ago
- Update Intl API documentation to include iOS support Summary: Original Author: jobpaardekooper@gmail.com Original Git: 28e1a338d06f3e45264b99a6da0e24ca277988ab As discussed in issue https://github.c... — committed to facebook/hermes by avp a year ago
Ok as a workaround you can use this function:
FYI, this is our plan for dealing with Intl problems: https://github.com/facebook/hermes/discussions/1211
@AndreiCalazans Thx. Even with
import '@formatjs/intl-numberformat/polyfill-force'(and forcing all of the other@formatjsimports) it remains slower than without polyfill. It has significant impact on the JS Thread. Still hoping for native support 🤞@jgo80 double check that formatjs ins’t using Hermes’ native Intl APIs since they are available formatjs won’t oveerride them. We had to patch shouldPolyfill calls within formatjs to always return true.
Hermes’ native Intl APIs are very slow.
@jobpaardekooper We could conditionally compile it out on older iOS versions, but this wouldn’t help in general until RN’s minimum iOS version is past 15+. (except for users who are willing to build Hermes from source)
is there a workaround for this? doesn’t work on android and ios for me
@AndreiCalazans I did not test it but in the docs at the Android 11 section it says notation: ‘compact’ has some rough edges on Android.
Regarding testing, we currently run against test262, which is the primary source of tests for both Android and iOS Intl implementations. You can take a look at our CI set-up here to see how it is done.
We also have some additional tests here that you can add to if you add features. Note that these are primarily for running on macOS.
Intl is enabled by default when you build with it, so you shouldn’t need to touch
-Xintlunless you want to disable it.