I wrote another proof of dollar formatting that will take any number (1, 1,6, 2,52, 8,24272) and automatically format it before notation in dollars ($ 1.00, $ 1.60, $ 2.52, $ 8.24):
$('.dollars').blur(function(e){
var curVal = parseFloat($(this).val()),
curInt = parseInt(curVal, 10),
curDec = parseInt(curVal*100, 10) - parseInt(curInt*100, 10);
curDec = (curDec < 10) ? "0" + curDec : curDec;
if (!isNaN(curInt) && !isNaN(curDec)) {
$(this).val("$"+curInt+"."+curDec);
}
});
See here in action.
mVChr source
share