Math object in javascript:
The Math object allows you to perform mathematical tasks.
The Math object includes several mathematical constants and methods.
Syntax for using properties/methods of Math:
var x=Math.PI;
var y=Math.sqrt(16);
Note: Math is not a constructor. All properties and methods of Math can be called by using Math as an object without creating it.
You may reference these constants from your JavaScript like this:
Math.E
Math.PI
Math.SQRT2
Math.SQRT1_2
Math.LN2
Math.LN10
Math.LOG2E
Math.LOG10E
Example code:
document.write(Math.round(4.7)); -- 5
document.write(Math.random()); -- any random value 0.3121296588253678
The following example uses the floor() and random() methods of the Math object to return a random number between 0 and 10:
document.write(Math.floor(Math.random()*11));
Script for getting random number <10 using JavaScript:
<script type="text/javascript">
no=Math.random()*10
document.write(Math.floor(no))
</script>
References:
http://www.cev.washington.edu/lc/CLWEBCLB/jst/js_math.html
http://www.javascriptkit.com/javatutors/math.shtml
Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif
Programmer123, if this helps please login to Mark As Answer. | Alert Moderator