JavaScript number-formatting library updated
I’ve released a new version of my powerful, flexible, efficient JavaScript number-formatting library, which is probably the best available. This release adds a fix for zero-padding negative numbers.
If you find bugs, please send me test cases I can use to reproduce and add to the unit test suite. One test per line, like “input”, “format”, “expected” is best. For example, this is a great test case:
-1, "#,#.00", "-1.00"
I can plug that directly into the unit test suite, run it, and if it gives back “-01.00″ it will fail the test. This makes it much easier and more convenient for me to fix bugs.
Sponsoring bug fixes wouldn’t hurt either ;-)



Hello,
your number formatting helped me lot. I just have two considerations :
- about licensing, could you double license it under LGPL and BSD/MIT or APACHE ? I’m writing an Apache-licensed project, and cannot integrate your lib as is due to licensing considerations.
- did you test your lib with Prototype ? I didn’t tested myself but I thing it may conflict with http://www.prototypejs.org/api/number.
Nicolas De Loof
10 Oct 07 at 10:24 am
I just discovered that both “#.0000″ and “#.####’ format 4 as “4.0000″. Is there any way to avoid those unecessary 0
Nicolas De Loof
10 Oct 07 at 11:34 am
It’s possible it may conflict with Prototype. I have not kept up with Prototype.
I don’t have time to look into the details of licensing right now, and I would need to understand the other licenses deeply to make that decision. You could dual-license your project if you wish.
I’m unclear from your description whether the 0′s are necessary. If you don’t want them, you can use “#.” instead, right? What use case doesn’t the existing behavior support? It’s supposed to be compatible with existing standards, so if it’s not, a test case and patch would be great.
Xaprb
10 Oct 07 at 12:50 pm
I can’t include your GPL code in an APACHE licensed project, as GPL requires me to license my work under GPL… For same reason I can dual license as the only license compatible with GPL is … GPL.
Fyi, APACHE/BSD/MIT licenses are recognized free software licenses taht allow the code to be included in any software (even commercial) with the only restriction NOT to use the author name as a trademark, and to keep in source code the original copyright notices.
The issue with “0″ is for formating 4 -> “4″ and 4.1 -> “4.1″ with the same pattern. From your test cases :
-> 4.5, “0.00″, “4.50″, // OK : fixed number of decimals
-> 4, “0.#”, “4.0″, // I expected : “4″ # should be for optional
Nicolas De Loof
11 Oct 07 at 4:26 am
that would also be nice to configure the group and decimal symbol beeing used. As a french user, I’m using “,” for decimals and ” ” for hundreds.
Nicolas De Loof
11 Oct 07 at 5:15 am