<SCRIPT><br><br><!--- Hide script from old browsers<br><br><br><br>// JavaScript based Scientific Calculator and demonstration of Math.* objects<br><br>// (C) 1996-7 Mohamed Ishan. 6-11-96 Completion time = 3 hours and 25 mins.<br><br>// anon4c9c@nyx.net<br><br><br><br>var been_there = 0; <br><br>var decimal_pt = 6; // global variable to hold the decimal point of numbers.<br><br><br><br><br><br>// This function makes sure a floating number has the correct<br><br>// decimal points as that defined by the user. Decimal point is<br><br>// initially, initlized to 6 points after the "."<br><br><br><br>function dec_pt(Value){<br><br> var temp, dec_pts = decimal_pt;<br><br><br><br> Value += "";<br><br> temp = Value.indexOf(".");<br><br> Value1 = Value.substring(0,temp) ;<br><br> Value2 = Value.substring(temp+1,temp+dec_pts+1) + "." + Value.charAt(temp+dec_pts+2);<br><br> Value2 = Math.round(Value2);<br><br> return(Value1 + "." + Value2);<br><br> <br><br>}<br><br><br><br><br><br><br><br>// compute(f) takes a form as an input, evaulates the result.value<br><br>// from the from.. and displays the output of the mathematical functions<br><br>// defined. This function also makes sure a number has a decimal point or<br><br>// not, if a number is a float or not..if so then it``s sent off to dec_pt<br><br>// to be rounded off to the correct decimal point.<br><br><br><br>function compute(f) {<br><br> f.result.value = eval(f.result.value);<br><br> temp = f.result.value.indexOf(".");<br><br><br><br> if(temp != -1) {<br><br> f.result.value = dec_pt(f.result.value);<br><br> }<br><br> <br><br> been_there=1; // tell jS that a value exists <br><br>} // inside result<br><br><br><br><br><br><br><br>function calcx(f, nums_oper) {<br><br><br><br> if (been_there==1) {<br><br> f.result.value = "";<br><br> been_there = 0 ;<br><br> }<br><br> f.result.value += nums_oper;<br><br>}<br><br><br><br><br><br>function ext_calc(f,oper) {<br><br> f.result.value = oper; been_there=1;<br><br>}<br><br><br><br>function Clear(f) {<br><br> f.result.value = "";<br><br>}<br><br><br><br>function changeDecimalPT(f) {<br><br> decimal_pt= parseInt(f.dec.value,10);<br><br> PI = dec_pt(Math.PI);<br><br>}<br><br><br><br>// end hiding from old browsers --><br><br></SCRIPT>