Click to See Complete Forum and Search --> : Online Calculator Result Formatting


mtyke
04-25-2006, 09:02 AM
I just made this online calculator yesterday. www.bluemarblestaffing.com/cost.htm My problem is once you click calculate and get the results, I would like them to include commas and be in currency form with two decimal places i.e. $xx,xxx.xx

Please let me know if you have a solution. Thanks in advance.

-Max

Fang
04-25-2006, 09:11 AM
http://www.alltheweb.com/search?cat=web&q=javascript%20currency%20format

mtyke
04-25-2006, 09:14 AM
Fang,
My stupid cyberguard blocks that website.. It says it's hacking/proxy avoidance. would you be able to copy and paste the article? Thanks

TiGGi
04-25-2006, 09:33 AM
<!-- TWO STEPS TO INSTALL CURRENCY FORMAT:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site: http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
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);
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<center>
<form name=currencyform>
Enter a number then click the button: <input type=text name=input size=10 value="1000434.23">
<input type=button value="Convert" onclick="this.form.input.value=formatCurrency(this.form.input.value);">
<br><br>
or enter a number and click another field: <input type=text name=input2 size=10 value="1000434.23" onBlur="this.value=formatCurrency(this.value);">
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 1.47 KB -->

mtyke
04-25-2006, 09:44 AM
Thanks for the info Tiggi, but how can I apply that to my form? Thanks

TiGGi
04-25-2006, 11:10 AM
copy and paste the script part and then add this to each of your fields:
onBlur="this.value=formatCurrency(this.value);"

mtyke
04-25-2006, 01:20 PM
Tiggi,
I've tried just copying step one into the head, and then inserting that onBlur after the input name, type and size but I still can't get it to format correctly. Thanks for your help so far, but I'm still having troubles.

TiGGi
04-25-2006, 01:52 PM
send me your form code and I'll do it on my side

mtyke
04-25-2006, 01:57 PM
This is the code for the whole form, inputs, outputs, and buttons. Thanks again for your help.


<TABLE height=784 cellSpacing=0 cellPadding=0 width=711 border=0><!-- MSTableType="layout" -->
<tr>
<TD vAlign=top colSpan=4 height=115><!-- MSCellType="ContentHead" --><img border="0" src="images/NEWBMSOLD.gif" width="711" height="115"></TD>
</tr>
<tr>
<TD vAlign=top bgColor=#0b50b4 rowSpan=4>
<P>&nbsp;</P>
<P><script id="vqp_generate_mainitems" language="javascript1.2">generate_mainitems()</script></P>
<P><!-- MSCellType="NavBody" --></P>
<P>&nbsp;</P>
<P>
<SCRIPT language=javascript1.2 id=vqp_generate_mainitems></SCRIPT>
</P>
<P><A href="../bm/mysite3/index.htm">
<SCRIPT language=javascript1.2 id=vqp_generate_mainitems></SCRIPT>
</A></P></TD>
<TD></TD>
<TD></TD>
<td height="2"></td>
</tr>
<tr>
<td>&nbsp;</td>
<TD vAlign=top height="34" colspan="2"><!-- MSCellType="ContentHead2" -->&nbsp;</TD>
</tr>
<tr>
<td>&nbsp;</td>
<TD vAlign=top align=justify><!-- MSCellType="ContentBody" -->
<P class=MsoNormal>&nbsp;</P>

<script language='Javascript'>
function compute(form) {
form.Hsave.value = (eval(form.acost.value - form.scost.value) * eval(form.replace.value));

form.Wsave.value = eval(form.Hsave.value) * 40;

form.Ysave.value = eval(form.Hsave.value) * 52 * 40;

form.Save3.value = eval(form.Hsave.value) * 52 * 40 * 3;
}

function ClearForm(form) {
form.agency.value = "";
form.replace.value = "";
form.acost.value = "";
form.scost.value = "";
form.Hsave.value = "";
form.Wsave.value = "";
form.Ysave.value = "";
form.Save3.value = "";
}</script>
<form method="post" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
<table BORDER="1" CELLSPACING="0" CELLPADDING="4">

<tr>
<td align="center" COLSPAN="2" bgcolor="#EEF5FF">
<font face='Tw Cen MT' color="#0B50B4"><strong>Cost Savings Calculator</strong> </font>
</td>
</tr>

<tr>
<td COLSPAN="2">
<p align="center">
<font face="Tw Cen MT">Blue Marble Staffing can reduce staffing costs for
healthcare facilities. Please use the calculator below to estimate your
potential savings. </font>

</td>
</tr>

<tr>
<td bgcolor="#0B50B4" colspan="2"><font face='Tw Cen MT' color="#EEF5FF">
<p align="center"><b>Your Information</b></td>
</tr>

<tr>
<td><font face="Tw Cen MT">Enter total number of agency
RNs:</font></td>

<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="agency" SIZE="4"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter number of agency RNs to be replaced:</td>
<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="replace" SIZE="4"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter hourly cost of agency RNs:</td>
<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="acost" SIZE="4"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter hourly cost of staff RNs:</td>

<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="scost" SIZE="4"></font></td>
</tr>


<tr>
<td align="center" colspan="2"><font size="3" face="Tw Cen MT">
<input TYPE="button" VALUE="Calculate" ONCLICK="compute(this.form)" style="font-family: Tw Cen MT; font-size: 12pt; color:#0B50B4; font-weight:bold; background-color:#EEF5FF"><input TYPE="button" VALUE="Clear Form" ONCLICK="ClearForm(this.form)" style="font-family: Tw Cen MT; font-size: 12pt; font-weight:bold; color:#0B50B4; background-color:#EEF5FF"></font></td>
</tr>

<tr>
<td bgcolor="#0B50B4" colspan="2"><font face='Tw Cen MT' color="#EEF5FF">
<p align="center"><strong>Your Savings</strong></td>
</tr>

<tr>
<td>
<font face="Tw Cen MT">Estimated Hourly Savings:</font></td>

<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Hsave" SIZE="9"></font></td>
</tr>

<tr>
<td>
<font face="Tw Cen MT">Estimated Weekly Savings:</font></td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Wsave" SIZE="9"></font></td>
</tr>

<tr>
<td>
<font face='Tw Cen MT'>Estimated Yearly Savings:</td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Ysave" SIZE="9"></font></td>
</tr>

<tr>
<td>
<font face='Tw Cen MT'>Estimated Savings After 3 Years:</td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Save3" SIZE="9"></font></td>
</tr>

</table>
</form><center>
</ul>
&nbsp;&nbsp;</TD>

TiGGi
04-25-2006, 04:29 PM
I removed your scripts and it works fine.
http://www.regencyhomes.com/test/calc.cfm
Try working with this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site: http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
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);
}
// End -->
</script>
<body>
<tr><TD vAlign=top align=justify><form method="post" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1">
<table BORDER="1" CELLSPACING="0" CELLPADDING="4">

<tr>
<td align="center" COLSPAN="2" bgcolor="#EEF5FF">
<font face='Tw Cen MT' color="#0B50B4"><strong>Cost Savings Calculator</strong> </font>
</td>
</tr>

<tr>
<td COLSPAN="2">
<p align="center">
<font face="Tw Cen MT">Blue Marble Staffing can reduce staffing costs for
healthcare facilities. Please use the calculator below to estimate your
potential savings. </font>

</td>
</tr>

<tr>
<td bgcolor="#0B50B4" colspan="2"><font face='Tw Cen MT' color="#EEF5FF">
<p align="center"><b>Your Information</b></td>
</tr>

<tr>
<td><font face="Tw Cen MT">Enter total number of agency
RNs:</font></td>

<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="agency" SIZE="4" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter number of agency RNs to be replaced:</td>
<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="replace" SIZE="4" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter hourly cost of agency RNs:</td>
<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="acost" SIZE="4" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

<tr>
<td><font face='Tw Cen MT'>Enter hourly cost of staff RNs:</td>

<td><font size="3" face="Tw Cen MT"><input TYPE="text" NAME="scost" SIZE="4" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>


<tr>
<td align="center" colspan="2"><font size="3" face="Tw Cen MT">
<input TYPE="button" VALUE="Calculate" ONCLICK="compute(this.form)" style="font-family: Tw Cen MT; font-size: 12pt; color:#0B50B4; font-weight:bold; background-color:#EEF5FF"><input TYPE="button" VALUE="Clear Form" ONCLICK="ClearForm(this.form)" style="font-family: Tw Cen MT; font-size: 12pt; font-weight:bold; color:#0B50B4; background-color:#EEF5FF"></font></td>
</tr>

<tr>
<td bgcolor="#0B50B4" colspan="2"><font face='Tw Cen MT' color="#EEF5FF">
<p align="center"><strong>Your Savings</strong></td>
</tr>

<tr>
<td>
<font face="Tw Cen MT">Estimated Hourly Savings:</font></td>

<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Hsave" SIZE="9" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

<tr>
<td>
<font face="Tw Cen MT">Estimated Weekly Savings:</font></td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Wsave" SIZE="9" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>


<tr>
<td>
<font face='Tw Cen MT'>Estimated Yearly Savings:</td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Ysave" SIZE="9" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

<tr>
<td>
<font face='Tw Cen MT'>Estimated Savings After 3 Years:</td>
<td><font size="3" face="Tw Cen MT">$<!--webbot bot="Validation" s-data-type="Integer" s-number-separators="," --><input TYPE="text" NAME="Save3" SIZE="9" onBlur="this.value=formatCurrency(this.value);"></font></td>
</tr>

</table>
</form><center>
</TD>
</body>
</html>

mtyke
04-26-2006, 08:10 AM
Good Morning Tiggi,

The top four fields are the input feilds, of which, the first two are just integer inputs and the last two are dollar amounts.

With the page that you made, the calculate button does not work, but the format for the output cells is correct. This is where I've been running into my problem, trying to use my script for the calculation AND trying to format the bottom four output cells with a currency format.

If you think that you'd be able to help me further with this dillema I would greatly appreciate it, but if not, I thank you tremendously for your help up to this point. Thanks!

TiGGi
04-26-2006, 08:26 AM
you didn't send me your JS files so I couldn't test it. IF you zip 'em and send to me I'll give it a try!

mtyke
04-26-2006, 08:36 AM
Bare with me as I am new to the programming world, but I don't believe that I have a java file... I think that it's just some simple calculations that I wrote in HTML format... if you go to www.bluemarblestaffing.com/cost.htm and view the source, this is all the programming that I have.

TiGGi
04-26-2006, 09:43 AM
Here your go:
http://www.regencyhomes.com/test/calc2.cfm
I did it kind of lazy way. You'll notice that I am calling currency function for each field from the Calculate button. I've placed currency function on the end of your JS.

mtyke
04-26-2006, 09:50 AM
Tiggi,
Thank you sooo much for you help. And the good news is, I understand what you did so I won't have to come to you with these remedial questions again! Thanks again, I really appreciate it.