Closed
Bug 1029540
Opened 10 years ago
Closed 10 years ago
ViewHelpers.L10N.numberWithDecimals doesn't properly handle NaN and numbers that can't be localized
Categories
(DevTools :: General, defect)
DevTools
General
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 33
People
(Reporter: vporof, Assigned: vporof)
References
Details
Attachments
(1 file, 1 obsolete file)
3.50 KB,
patch
|
bgrins
:
review+
|
Details | Diff | Splinter Review |
numberWithDecimals(0.0001, 2) // "00"
It should be "0" or "0.0" or "0,0" instead, but since we don't know the localization settings ("," or "."?), we should simply return "0".
Assignee | ||
Comment 1•10 years ago
|
||
Comment 2•10 years ago
|
||
Comment on attachment 8445222 [details] [diff] [review]
v1
Review of attachment 8445222 [details] [diff] [review]:
-----------------------------------------------------------------
I think browser.ini needs to be rebased. Looks good besides that, just a couple of questions about the early return.
::: browser/devtools/shared/widgets/ViewHelpers.jsm
@@ +375,5 @@
> let localized = aNumber.toLocaleString(); // localize
> +
> + // If no grouping or decimal characters are available, bail out, because
> + // padding with zeros at the end of the string won't make sense anymore.
> + if (!localized.contains(".") && !localized.contains(",")) {
I'm actually not sure what case this is catching. Is this just an early return to prevent some computation or is this actually changing the output of the function? For instance, if I run l10n.numberWithDecimals(123, 10); with or without the patch, I get the same result.
Also, do all locales use , for grouping?
Attachment #8445222 -
Flags: review?(bgrinstead)
Comment 3•10 years ago
|
||
> I'm actually not sure what case this is catching. Is this just an early
> return to prevent some computation or is this actually changing the output
> of the function? For instance, if I run l10n.numberWithDecimals(123, 10);
> with or without the patch, I get the same result.
Scratch that, I see the case in the first comment
Comment 4•10 years ago
|
||
With the patch applied:
l10n.numberWithDecimals(0.0001, 2); // "0"
l10n.numberWithDecimals(0.001, 2); // "0.00"
l10n.numberWithDecimals(1.00001, 2) // "1"
I'm not really sure what the right result here is, but it is a bit odd that some decimals become NUM and some become NUM.00. Luckily this also fixed what looks like a really bad bug without the patch applied:
l10n.numberWithDecimals(1.00001, 2) // "10" ? huh
Assignee | ||
Comment 5•10 years ago
|
||
This is Number.toLocaleString misbehaving. There's nothing I can do about that, like for 0.0001 vs. 0.001.
Assignee | ||
Updated•10 years ago
|
Attachment #8445222 -
Flags: review?(bgrinstead)
Assignee | ||
Comment 6•10 years ago
|
||
Addressed comments from the discussion on IRC.
Attachment #8445222 -
Attachment is obsolete: true
Attachment #8445222 -
Flags: review?(bgrinstead)
Attachment #8445262 -
Flags: review?(bgrinstead)
Comment 7•10 years ago
|
||
Comment on attachment 8445262 [details] [diff] [review]
v2
Review of attachment 8445262 [details] [diff] [review]:
-----------------------------------------------------------------
Changes LGTM
Attachment #8445262 -
Flags: review?(bgrinstead) → review+
Assignee | ||
Comment 8•10 years ago
|
||
Whiteboard: [fixed-in-fx-team]
Comment 9•10 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Whiteboard: [fixed-in-fx-team]
Target Milestone: --- → Firefox 33
Updated•6 years ago
|
Product: Firefox → DevTools
You need to log in
before you can comment on or make changes to this bug.
Description
•