Java Reference
In-Depth Information
The Math.round() method will round a number to the nearest integer:
> Math.round(4.5);
<< 5
> Math.round(4.499);
<< 4
> Math.round(-4.2);
<< -4
The Math.exp() method will raise a number to the power of Euler's constant:
> Math.exp(1); // This is Euler's constant
<< 2.718281828459045
> Math.exp(0); // Any number to the power of 0 is 1
<< 1
> Math.exp(-3);
<< 0.04978706836786393
The Math.pow() method will raise any number (the first argument) to the power of an-
other number (the second argument):
> Math.pow(3,2); // 3 squared
<< 9
> Math.pow(4.5,0); // Any number to the power of 0 is 1
<< 1
> Math.pow(27,1/3); // A nice way to do cube roots
<<
The Math.sqrt() method returns the positive square root of a number:
> Math.sqrt(121);
<< 11
Search WWH ::




Custom Search