»
EnglishFrenchVietnamese

Print - Calculator with memorial function - JavaScriptBank.com

Full version: jsB@nk » Calculation » Calculator » Calculator with memorial function
URL: http://www.javascriptbank.com/calculator-with-memorial-function.html

Calculator with memorial function © JavaScriptBank.comThis JavaScript create a simple calculator with memorial function.

Full version: jsB@nk » Calculation » Calculator » Calculator with memorial function
URL: http://www.javascriptbank.com/calculator-with-memorial-function.html



CSS
<style>.cabutt{background-color: #FFEECC; color: #3366CC; width: 100%; height: 50;  position: relative; border-style: solid; border-color: #FFEECC}.cdbutt{background-color: #000080; color: #FFEECC; height: 50;  position: relative;border-style: solid; border-color: #000080}</style><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script language="JavaScript"><!-- Startvar value1 = "", value2 = "", value3 = "0"var value4 = "done", num = 0, mvalue = 0; function nkey(i) {  if (num == 1) {      value1 = value2; value2 = value3;     value3 = "" + i; value4 = "eidt"; num = 2;   } else {      if (value4 == "done" || value3 + "" == "0")     { value3 = "" + i; value4 = "eidt"; }      else { value3 += "" + i; }  }  more(); }function ptkey() { if (value4 != "point")  {    if (value4 == "done") {     if (num != 1) { ckey(0); }      nkey("0.");   } else { value3 += "."; more(); }   value4 = "point";  }} function more() { document.cform.V1.value = value1 + " " + value2 + " " + value3;}function fkey(j) { if (num != 1) {   value2 = eval(value1 + value2 + value3); value1 = "";    value2 = round(value2); num = 1; value4 = "done"; } value3 = j; more();}     function rkey(j) { if (num != 1) { if (j == "%") {     value3 = value3 * 0.01;    }    if (j == "=") {     value3 = eval(value1 + value2 + value3);      value2 = ""; value1 = ""; num = 0;   }   value3 = round(value3); more(); value4 = "done";  }}function ckey(k) { if (k == 0) { if (value2 != "")    { value3 = value2; } else { value3 = "0"; }   value2 = value1; value1 = "";   if (num == 2) { num = 1; } else { num = 0; } }  if (k == 1) {   value3 = "0"; value2 = ""; value1 = ""; num = 0; } more(); value4 = "done"; }function mvkey(k) { if (num == 0) {   if (k == "+") { mvalue = mvalue + eval(value3); }   if (k == "-") { mvalue = mvalue - eval(value3); }   mvalue = round(mvalue); setmemo(); value4 = "done";  }}function mckey(k) { if(k == "=") {   if (num != 1) { ckey(0); }   nkey(mvalue); value4 = "done";  } if (k == "c") { mvalue = 0; setmemo(); } }function setmemo() {  document.cform.V2.value = "";  if (mvalue != 0) {    document.cform.V2.value = "<M> " + mvalue + "; ";  }}function sbkey() { value2 = altsb(value2 + "");  value3 = altsb(value3 + ""); more();} function altsb(sb) { if (sb == "") { value3 = - eval(value3) + ""; } if (sb == "+") { return "-"; } if (sb == "-") { return "+"; } if (sb == "*") { return "/"; } if (sb == "/") { return "*"; } return sb; }function round(rndval) { var full = rndval + "", endstr = "";  if (full.indexOf('.') < 0) { return rndval; }  if (eval(full.substring(0, full.indexOf('.') + 9)) == 0)  { return rndval; } var cutsize = full.length;  if (full.indexOf('e') > 0 ) {   cutsize = full.indexOf('e') - 1;    endstr = full.substring(cutsize + 1, full.length);  } var cutstr = full.substring(full.indexOf('.'), cutsize);  cutsize = cutstr.length; if (cutsize > 9) {   var addup = 1;   full = full.substring(0, full.indexOf('.'));    for (var x=0; x<cutsize - 1; x++) {addup *= 0.1;}   cutstr = (addup*4 + eval(cutstr)) + "";   var cutlen = cutstr.length;    if (cutstr.indexOf('e') != -1) { return rndval; }    if (cutsize - cutlen > 4) {     return eval(full + cutstr.substring(1, cutlen)) + endstr;    }   cutstr = cutstr.substring(0, cutstr.length - 2);    cutstr = eval(cutstr) + "";   if (cutstr.indexOf('e') != -1) { return rndval; }    if (cutlen - cutstr.length > 4) {     return eval(full + cutstr.substring(1, cutstr.length)) + endstr;    } } return rndval; }// END / Many more are available free online --></SCRIPT><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<table width="auto" height="350" border="0" align="center" cellpadding="25" cellspacing="1"   bgcolor="silver" class="main0">  <tr>     <td align="center" colspan="2" bgcolor="#FFFFFF"><table border="0" width="350" height="250"       cellpadding="2" bgcolor="#FFCC99"><form class="liform" name="cform">   <tr>    <td width="100%" bgcolor="#FFEECC" colspan="6" height="50">  <table border="0" width="100%" height="100%"      cellspacing="0" cellpadding="0" bgcolor="#000080">        <tr>          <td width="350" align="right" colspan="2"><nobr>             <input type=button class="cdbutt" name="V2">               <input type=button class="cdbutt" name="V1">        </nobr></td>        <tr>          <td width="310" align="center" height="25" bgcolor="#FFEECC">            <nobr><font face="Arial" size="2"><a href="http://javascriptbank.com/">JavaScriptBank.com</a></font></nobr></td>          <td width="40" height="25" bgcolor="#FFEECC">            </td>        </tr>      </table>    </td>  </tr>  <tr>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="1" onClick="nkey(1)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="2" onClick="nkey(2)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="3" onClick="nkey(3)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="+" onClick='fkey("+")'></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="+/-" onClick="sbkey()"></td>    <td width="100" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="C" onClick="ckey(1)"></td>  </tr>  <tr>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="4" onClick="nkey(4)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="5" onClick="nkey(5)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="6" onClick="nkey(6)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="-" onClick='fkey("-")'></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="M+" onClick='mvkey("+")'></td>    <td width="100" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="CE" onClick="ckey(0)"></td>  </tr>  <tr>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="7" onClick="nkey(7)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="8" onClick="nkey(8)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="9" onClick="nkey(9)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="*" onClick='fkey("*")'></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="M-" onClick='mvkey("-")'></td>    <td width="100" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="MC" onClick='mckey("c")'></td>  </tr>  <tr>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="." onClick="ptkey()"     style="font-weight: bold"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="0" onClick="nkey(0)"></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="%" onClick='rkey("%")'></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="/" onClick='fkey("/")'></td>    <td width="50" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="M" onClick='mckey("=")'></td>    <td width="100" bgcolor="#FFEECC" height="50"><input class="cabutt" type=button value="=" onClick='rkey("=")'></td>    </tr></form></table><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->