CancelImage Upload

How to calculate the square route of a number using JavaScript

To calculate the square route of a number in JavaScript, we need to use it's Math Object. By adding the square route extension (sqrt) and specifying the number inside the brackets, we can calculate the square route:

var sqrt = Math.sqrt(number);

Here is a more extensive example of the function being used within a HTML document, and the value being returned via a JavaScript alert():

<html>
<head>
<title>How to calculate the square route of a number in JavaScript</title>
<script language="JavaScript">

function sqrt()
{

       var sqrt = Math.sqrt(25);

       alert(sqrt);

}

</script>
</head>
<body onload="javascript:sqrt();">

</body>
</html>

To find out how to round the square routs up or down, or rounding up or down any number for that matter, read the following tutorial:

How to round numbers to a specific decimal point in JavaScript

Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com