js实现分数计算器的方法,js实现分数计算器的代码教程如下:
实现结果:实现分数的加减乘除
js实现代码如下:
http://www.itmop.com///hksfgfdda///0....///
<!-- jumpstart calculator
function launch(file)
{
hwnd = window.open(
file,"calc","toolbar=no,directories=no,menubar=no, width=600,height=170");
hwnd = window.open(file,"calc");
}
function intDivide( n1, n2 ){
var n = 0;
while (n1 >= n2 ){
n++;
n1 -= n2;
}
return n;
}
//--- simplify fraction
//--- determine greatest common divisor
function simplify( n1, n2 )
{
var min = ( n1 > n2 ) ? n2 : n1;
var gcd =1;
for( var i=1;i<=min; i++) if ( ( n1 % i == 0 ) && ( n2 % i ) == 0 ) gcd =i;
f = ( n1 / gcd ) + "/" + ( n2 / gcd );
return f;