codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Multiplying currency  Robert Chapman at 14:59 on Friday, April 23, 2010
 

i need to have a number put into field1 and displayed in field1 as currency and at the same time be multiplied by 50 and displayed in field2 as currency. Right now i have it were field1 can be displayed as a number then multiplied by 50 and shown in field2 as currency, but when i make field1 display as currency field2 shows $0.00 i think this is due to the fact that the numbers in field1 now have currency symbols in them....... is there a way to make a number be diplayed as currency and multiplied at the same time i will paste the code i'm using thanks



<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>



<script type="text/javascript">

function docomputation(form) {

var result ;
var val = form.Input.value ;
if (val.length==0 || isNaN(val)) {
result = 0 ;
} else {
result = 50 * val ;
}
form.Input2.value = formatCurrency(result.toString()) ;

return 1 ;

}

function formatCurrency(num) {
num = num.replace(/\$|\,/g,'') ;
if (isNaN(num)) {
num = "0" ;
}
sign = (num == (num = Math.abs(num))) ;
num = Math.floor(num*100+0.50000000001) ;
num = Math.floor(num/100).toString() ;
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);
}

</script>






<form id="Calc" name="Calc" method="post" action="" >
<span style="font-family: 'Times New Roman', Times, serif; font-size: 16px; color: #060; padding-left: 110px;">If you want to save </span>
<input onfocus="this.value=''" type="text" value="Enter Amount" id="Calcname" onkeydown="docomputation(this.form)" onkeyup="this.value=formatCurrency(this.value);" style="font-size:14px; color: #060; font-family: 'Times New Roman', Times, serif; text-align: right;" name="Input" size="15" />
<span style="font-family: 'Times New Roman', Times, serif; font-size: 16px; color: #060;">, you</span><br />
<span style="font-family: 'Times New Roman', Times, serif; font-size: 16px; color: #060; padding-left: 100px;">would need to create </span>
<input id="Calcname2" style="font-size:14px; color: #060; font-family: 'Times New Roman', Times, serif; text-align: right;" name="Input2" size="15" type="text" />
<span style="font-family: 'Times New Roman', Times, serif; font-size: 16px; color: #060;"> in new revenue.</span><br />
<div style="padding-bottom:10px; text-align: center;"><span style="font-family: 'Times New Roman', Times, serif; font-size: 10px; color: #060;">* Based on a 2% operating margin.</span></div>
<div style="text-align:center"><span style="font-family: 'Times New Roman', Times, serif; font-size: 16px; color: #060;">VIE can save you at least $100,000.00<br />
starting with our self-funded analysis.<br />
Give us a call today!</span></div>
<div style="text-align:center"><img src="/forum/images/viegraph.png" width="582" height="299"><img name="" src="images/callvieguy.png" width="390" height="231" alt=""></div>

</form>








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  image and form fieild upload problem
•  Multiplying currency
•  Java Garbage Collection Boot Camp
•  validations fo form fields
•  Setting page size at which scroll bars appear in browser window (javascript)
•  before executing a function
•  how to write a code in asp.net to create a glossary .
•  I am trying to run a programme which is using PGPLOT.When I call it from browser I get following error message.
•  Re: open excel file in html page


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010