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.jsExamples:
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ı
Comments