Monthly Archives: April 2008

slickifying Slikcalc to version 1.0

A new version of Slikcalc (1.0) was released. This release simplified some code, mainly the slikcalc.formatCurrency() method. There was also a bug where a calculator could be initialized more than once depending on timing that was fixed. As always, feel free to leave feedback on the library. Enjoy. Download Slikcalc 1.0

Tagged , | Leave a comment

Format Currency in Javascript (simplified)

While working on Slikcalc, I was trying to find the easiest way to format a number for currency. I had found some implementations that were pretty complex, using regex and absolute values, and thought there had to be a simpler way. This is what I came up with and so it works great in all the browsers I’ve tested (IE 6/7, Firefox 2 (windows & mac), Opera 9 (windows and mac).

function formatCurrency(num) {
  num = isNaN(num) || num === '' ? 0.00 : num;
  return parseFloat(num).toFixed(2);
}

Just thought I’d share for anyone working with something similar.

Tagged , | 32 Comments

Page optimized by WP Minify WordPress Plugin