JavaScript DecimalFormat

We needed to implement a number formatter in JavaScript for Formspider, our Web 2.0 framework for PL/SQL developers. The applications developed with the framework can run on both Java and JavaScript from the same code base. Since we used the DecimalFormat on Java side, we needed the same functionality for the Javascript environment as well. The Javascipt code below implements Java's DecimalFormat in JavaScript.
It is implemented to fulfill our basic needs such as prefix, suffix, comma separation, min/max digits and percentage(%) values.

Here is the source code: DecimalFormat.js

var df = new DecimalFormat("$#,#00.00#");
df.format(1); //$01.00
df.format(12345.6789); //$12,345.679
df.formatBack("$1,234.00"); //1234

For detailed information you can visit Java DecimalFormat description page.

Öskan Şavlı


very cool & good js tool, thank you very much for sharing.
Greg said…
What is this licensed under?
Gerger said…
Greg, consider it a gift.
Hi. I use the Formspider.
How can I set ' '(space) instead of a ','(comma)?

For example, 1000000 => 1 000 000
I use the Formspider.
How can I set a space(' ') instead of a comma(',')?

For example, 1000000 => 1 000 000

Popular posts from this blog

Monitoring Oracle Database with Zabbix

Powerful Free Webinar Network for Oracle Developers