-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Intl.NumberFormat disregards maximumSignificantDigits #22156
Comments
@nodejs/intl @nodejs/v8 |
These are results with some relevant Node.js and V8 (Windows 7 x64, common Node.js builds with new Intl.NumberFormat(undefined, { maximumSignificantDigits: 1 }).format(1234560)
|
|
|
|
so right now i'm concerned about this
and 3 kinda ≠ 6 |
|
|
There's an ICU bug. https://unicode-org.atlassian.net/browse/ICU-20063 // @sffc |
v8 is broken too unless they've mitigated this. here's a hackaround that diff --git a/deps/v8/src/objects/intl-objects.cc b/deps/v8/src/objects/intl-objects.cc
index 60c3a0721b..adbb6b460e 100644
--- a/deps/v8/src/objects/intl-objects.cc
+++ b/deps/v8/src/objects/intl-objects.cc
@@ -274,20 +274,31 @@ void SetNumericSettings(Isolate* isolate, icu::DecimalFormat* number_format,
number_format->setMaximumFractionDigits(digits);
}
- bool significant_digits_used = false;
+ int32_t mndig = -1;
+ int32_t mxdig = -1;
+ bool mndig_used = false;
+ bool mxdig_used = false;
if (ExtractIntegerSetting(isolate, options, "minimumSignificantDigits",
- &digits)) {
- number_format->setMinimumSignificantDigits(digits);
- significant_digits_used = true;
+ &mndig)) {
+ mndig_used = true;
}
if (ExtractIntegerSetting(isolate, options, "maximumSignificantDigits",
- &digits)) {
- number_format->setMaximumSignificantDigits(digits);
- significant_digits_used = true;
+ &mxdig)) {
+ mxdig_used = true;
}
- number_format->setSignificantDigitsUsed(significant_digits_used);
+ // per https://unicode-org.atlassian.net/browse/ICU-20063
+ // the following call trashes the min/max settings. So call it first.
+ number_format->setSignificantDigitsUsed(mndig_used || mxdig_used);
+
+ // Now it's safe to call set min/max
+ if(mndig_used) {
+ number_format->setMinimumSignificantDigits(digits);
+ }
+ if(mxdig_used) {
+ number_format->setMaximumSignificantDigits(digits);
+ }
number_format->setRoundingMode(icu::DecimalFormat::kRoundHalfUp);
} |
v8 does NOT have a mitigation for this that I could see… https://github.com/v8/v8/blob/master/src/objects/intl-objects.cc#L294 … so v8 is broken, depending on the ICU version used. but :( looks like v8 put a hack into its ICU version — here is the patch it might be better to just put this same patch into node's ICU for this specific version. |
@jskeate @vsemozhetbyt I committed a workaround patch in |
node 10.11 still has this issue - the history is a little hard for me to read, other than that this issue is still marked Open. Can I please get a recap?
expected: Chrome debugger 69.0.3497.100 (Official Build) (64-bit) gives the right answer - no idea if that's relevant. ICU's tracked issue looks to be marked resolved 3 days ago. |
@JasonKleban OK, sorry. Looks like I did not open a PR for master...srl295:patch-icu-62-sigdig … and also #23715 brings in 63.1 which fixes this. let me see what I can do. |
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: nodejs#22156 PR-URL: nodejs#23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
ICU 62.1 had a bug where certain orders of operations would not work with the minimum significant digit setting. Fixed in ICU 63.1. Applied the following patch from v8. https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1128503 ICU Bug: https://unicode-org.atlassian.net/browse/ICU-20063 Fixes: #22156 PR-URL: #23764 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Previously (node v9.2, at least), this behaved correctly:
The text was updated successfully, but these errors were encountered: