Opened 8 years ago

Closed 6 years ago

#9017 closed defect (patchwelcome)

dojo.number.format with 0 leading zeros shows one leading zero

Reported by: bmilcke Owned by: peller
Priority: high Milestone: future
Component: General Version: 1.3.0rc2
Keywords: Cc:
Blocked by: Blocking:


dojo.number.format(0.123, { pattern: "#.##"}); returns "0.12" instead of ".12".

Change History (5)

comment:1 Changed 8 years ago by bmilcke

sorry, forgot the component. Cannot change this now, obviously.

comment:2 Changed 8 years ago by peller

@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 8 years ago by bmilcke

Well at 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 8 years ago by peller

  • Milestone changed from tbd to future
  • Owner changed from anonymous to 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 6 years ago by peller

  • Resolution set to patchwelcome
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.