FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Calculating FormattedCurrency





alone
currently am using this code I got from "The Javascript Source", to turn the numbers on "onblur" into currency.


Code:

<SCRIPT LANGUAGE="JavaScript">
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/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));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
</script>



What I want to do is an autosum where as numbers are entered the input box with the total is updated automatically. I got this code from "The javascript Code" as well for doing this.


Code:

<script type="text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
document.autoSumForm.thirdBox.value = (one * 1) + (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
</script>



The problem I have with the code is that the first code I use adds commas, decimals, and dollars signs so I get the NaN in the total input field.

IS there a way of adding currency. OR is there a simpler code that formats number to currency on "onblur" (like the first code) and then it autosums them like the second code.
Related topics
One Liners for Code Cowboys
Creating a new Operating System
useless posts
calcilation machine for php
Hurricane set to lash New Orleans
Will Jesus Return ? WHEN / HOW ...
Why did I get 13.1 kb/s download speed on dialup?
Big Errors in Poins
Guide to set up a free .be domain name.
Just in case this hasn't been seen (Iraqi death toll)
The Perfect Audio Rips
Howto centre an object vertical using css?
HELLO ALL "rank this gaming site"
Ancient Greek calculating device continues to reveal secrets
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.