Advertisement
Advertisement
| 02.07.2008 at 10:42AM PST, ID: 23145397 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: |
function formatCurrency(fld, curPrefix) {
//Get rid of any thing other than numbers and decimal places.
if(fld.value == ""){
}
else
{
num = fld.value;
num = num.toString().replace(/[^0-9.]/g,'');
if(isNaN(num)) num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
}
// Comment next line you do not want 2 decimal places.
//fld.value = ( ( (sign)?'':'-') + curPrefix + num + '.' + cents);
//return (((sign)?'':'-') + curPrefix + num + '.' + cents);
// UnComment next line you do not want 2 decimal places.
fld.value = (((sign)?'':'-') + curPrefix + num);
return (((sign)?'':'-') + curPrefix + num);
}
}
|