News for hackers. Stuff that matters.
Re:Java DecimalFormat implemented in JavaScript by bluedevil2k on Thursday February 10, 2011 @10:45AM (#2202255)
Here's a much more robust number formatter for JavaScript, written as a jQuery plugin.

http://code.google.com/p/jquery-numberformatter/

Re:Java DecimalFormat implemented in JavaScript by euroclydon on Thursday February 10, 2011 @10:34AM (#2202207)
Re:Java DecimalFormat implemented in JavaScript by oskansavli on Friday February 11, 2011 @08:31AM (#2206253)
As stated in the blog, the Formspider framework had a Java renderer that uses DecimalFormat and we needed the same functionality on the javascript side which means formatting numbers with variable masks such as "$#,#00.0#" or "00.0##%" that is defined by the user. So sprintf is not the same. By the way, this code was wrtiten in 2008.
Re:Java DecimalFormat implemented in JavaScript by huherto on Thursday February 10, 2011 @10:49AM (#2202270)
In the case of currency, it is better to use decimal arithmetic because if you use float numbers the rounding behaves different than doing the same operations by hand or in a calculator. Another option is to use integers (to represent number of cents) and just print the decimal point when displaying the number.
Re:Java DecimalFormat implemented in JavaScript by euroclydon on Thursday February 10, 2011 @11:14AM (#2202357)
I'm not sure if you're answering my question or not. I've inspected the source of both libraries, and they both use the JS method toFixed().
Re:Java DecimalFormat implemented in JavaScript by huherto on Thursday February 10, 2011 @03:55PM (#2203669)
Never mind, you are right it is just to format decimals.
Re:Java DecimalFormat implemented in JavaScript by serdarbicer on Thursday February 10, 2011 @04:32PM (#2203856)
I'm not sure that it does the same job.