What is the use of Math Object in JavaScript? [Resolved]

Posted by Programmer123 under JavaScript on 9/24/2013 | Points: 10 | Views : 1063 | Status : [Member] | Replies : 4
What is the use of Math Object in JavaScript?




Responses

Posted by: Bandi on: 9/25/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
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

Posted by: Allemahesh on: 9/25/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
The math object provides you properties and methods for mathematical constants and functions.

var x = Math.PI; // Returns PI
var y = Math.sqrt(16); // Returns the square root of 16
var z = Math.sin(90); Returns the sine of 90


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 9/25/2013 [Member] Starter | Points: 25

Up
0
Down
http://www.w3schools.com/js/js_obj_math.asp
http://www.javascriptkit.com/javatutors/math.shtml#.UkJj5z9mM_I
http://www.javascripter.net/faq/mathfunc.htm

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 9/25/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
refer this link i hope it will help you
http://www.dummies.com/how-to/content/how-to-use-javascripts-math-object-to-program-with.html

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response