Number Format Heaven

ComputingOpen Source

Well here’s a happy ending ……. I have a working solution to this [hell][1].

I did not try any of the solutions I wrote up in the comments of the hell post. I just woke up the next morning realising it was even simpler.

The solution to getting Cocoon and Dojo using the same localised formats for numbers, was to use Java classes that are built using the same [CLDR][2] data as Dojo.

I now use the NumberFormat classes from [com.ibm.icu.text][3] instead of [java.text][4], to send and receive formatted numbers. It was almost a drop-in replacement.

The IBM versions have their format data compiled from the same source as Dojo. While java.text.*’s data seems to be really stale.

Choose the version that uses the same CLDR version as Dojo. Dojo 1.1.1 uses CLDR 1.5.1 so wants [icu4j version 3.8.1][5] and Dojo 1.2 will use CLDR 1.6 which comes in [icu4j 4.0][6] (so there is a clear upgrade path).

Here’s one happy bunny.

The one remaining fly in the ointment is languages like Hindi and Arabic, that use different Unicode characters for digits, which is really ironic as supposedly zero came from India and the 1 to 9 came from Arabia, (imagine trying to do maths with Roman numerals!!) probably the next thing to try is re-building Dojo’s locale number libraries with everything included.

[1]: {% post_url 2008-07-29-number-format-hell %} [2]: http://www.unicode.org/cldr/ [3]: http://icu-project.org/apiref/icu4j/com/ibm/icu/text/package-summary.html [4]: http://java.sun.com/j2se/1.4.2/docs/api/java/text/package-summary.html [5]: http://icu-project.org/download/3.8.html#ICU4J [6]: http://icu-project.org/download/4.0.html#ICU4J