Javascript Math Reference : Square Root
Javascript Math.sqrt
As its name indicate Math.sqrt(x) returns the square root of x. Take at the following example
<html> <body> <script type="text/javascript"> <!-- /* ******************************************************** Example - Usage of Math.sqrt ******************************************************** */ var x = 49; var z = Math.sqrt(x); // Outputs 7 var y = Math.sqrt(12.23) ; // Outputs 3.4971416900091423 var p = Math.round(Math.sqrt(12.23)*1000)/1000 ; // Truncating to 3 decimal places document.write ('Math.sqrt(49) is : ' + z + '<br>'); document.write ('Math.sqrt(12.23) is : ' + y+'<br>' ); document.write ('Math.sqrt(12.23) to two decimal place is : ' + p+'<br>' ); //--> </script> </body> </html> |
Try this example online here .