Привет Шубх и Мэтт Мейджор Спасибо !!!!мне удается сделать это через следующее.
function round(d)
// Returns a number rounded to 4 decimal places.
{ var multiplier = 10000;
return Math.round(d*multiplier) / multiplier;
};
function negative(n)
{ if(n<0)
complain("Negative input");
return (n<0);
}
function calculate(vdiam,vlen,vdepth){
//var vdiam = 1.08;
//var vlen = 2.40;
//var vdepth = 0.72;
var res = 0; //result
//Convert inputs to numbers
d = new Number(vdiam);
l = new Number(vlen);
h = new Number(vdepth);
r = d/2;
if(negative(d)) return;
if(negative(l)) return;
if(negative(h)) return;
//make sure it's all kosher
if(h>d)
{ console.log("Depth exceeds diameter");
return;
}
//calculate
var segArea =r*r*Math.acos((r-h)/r) - (r-h)*Math.sqrt(2*r*h-h*h);
res = segArea*l;
if(isNaN(res))
{ console.log("Inputs must be positive numbers");
res = "";
return;
}
res = res*1000;
return round(res);
}
alert(calculate(1.08,2.40,0.72));