Opened 10 years ago

Closed 7 years ago

#10843 closed defect (patchwelcome)

dojo.number.format does not support spaces

Reported by: clinejm Owned by: Adam Peller
Priority: high Milestone: 1.9
Component: Core Version: 1.4.0
Keywords: Cc:
Blocked By: Blocking:

Description

If you supply a pattern that includes spaces the formatter will stop after the first space:

<input dojotype="dijit.form.NumberTextBox?" constraints="{pattern: '# ##0.00'}" id="testText" name="testText"/>

an input of 123456789 will result in:

123,456,789 ###,00

I've tested in 1.3 and 1.4 with the same results.

Change History (8)

comment:1 Changed 10 years ago by clinejm

The example pattern is specifically referenced in http://www.unicode.org/reports/tr35/#Number_Format_Patterns which dojo.number.format references in the documentation

comment:2 Changed 10 years ago by Adam Peller

Milestone: tbd1.5
Owner: changed from anonymous to Adam Peller
Status: newassigned

Not sure this example was there when dojo.number was implemented, but it certainly appears to be a bug. I suppose any character not on the special list should be passed through.

comment:3 Changed 10 years ago by Adam Peller

a testcase:

Index: number.js
===================================================================
--- number.js	(revision 21565)
+++ number.js	(working copy)
@@ -330,6 +330,8 @@
 	//change decimal places
 	t.is("-1\xa0000,100", dojo.number.format(-1000.1, {places:3, locale: "fr-fr"}));
 	t.is("-1,000.100", dojo.number.format(-1000.1, {places:3, locale: "en-us"}));
+
+	t.is("1 234,57", dojo.number.format(1234.57, {pattern: "# ##0.00", locale: "fr-fr"}));
 			}
 		},
 		{

comment:4 Changed 10 years ago by Adam Peller

I'm starting to doubt this is going to make 1.5. I trust you're able to work around this?

comment:5 Changed 10 years ago by Adam Peller

(In [21732]) add comment to reflect that literals are not supported in number patterns. Refs #10843

comment:6 Changed 10 years ago by Adam Peller

Milestone: 1.5future

comment:7 Changed 10 years ago by Adam Peller

note that characters like '.' and ',' still have special meaning and are localized, according to the spec. ' ' for a thousands separator can be achieved by choosing a locale which supports this, like fr, or perhaps by calling dojo.number._formatAbsolute directly and providing explicit separator characters to override the localized behavior (should this be made public?)

comment:8 Changed 7 years ago by dylan

Component: GeneralCore
Milestone: future1.9
Resolution: patchwelcome
Status: assignedclosed

A patch would be welcomed to fix this. For now, closing due to lack of activity in creating a solution for this.

Note: See TracTickets for help on using tickets.