Opened 12 years ago
Closed 9 years ago
#9017 closed defect (patchwelcome)
dojo.number.format with 0 leading zeros shows one leading zero
Reported by: | bmilcke | Owned by: | Adam Peller |
---|---|---|---|
Priority: | high | Milestone: | future |
Component: | General | Version: | 1.3.0rc2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
dojo.number.format(0.123, { pattern: "#.##"}); returns "0.12" instead of ".12".
Change History (5)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
@bmilcke, try pattern: "0.##" I know this pattern stuff seems ambiguous (tried to implement from CLDR which copies from Java) but I think you're really supposed to have at least one '0' in the pattern? (General component is fine, btw)
comment:3 Changed 12 years ago by
Well at http://unicode.org/reports/tr35/#Number_Format_Patterns it is stated:
For consistency in the CLDR data, the following conventions should be observed so as to have a canonical representation:
- All formats should have one 0 before the decimal point (for example, avoid #,###.##)
So, it is correct that you should avoid it. However I find the result unexpected.
- All number patterns should be minimal: there should be no leading # marks except to specify the position of the grouping separators (for example, avoid ##,##0.###).
Well, at least I don't really understand this then, or there is a bug in Dojo?
dojo.number.format(123, {pattern:"0.##"}); -> 3
dojo.number.format(123, {pattern:"#0.##"}); -> 123
So, you need a leading #.
comment:4 Changed 12 years ago by
Milestone: | tbd → future |
---|---|
Owner: | changed from anonymous to Adam Peller |
You're right, the latter part is probably a bug, but one with a workaround. I really hate that spec. It's unnecessarily complex.
comment:5 Changed 9 years ago by
Resolution: | → patchwelcome |
---|---|
Status: | new → closed |
sorry, forgot the component. Cannot change this now, obviously.