home gear home donate
Search Results For

Libraries book

HTML Library CSS Library JavaScript Library PHP Library


PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous


Website Hosting Developer Q+A
Sprite Programming Mastery
Math Object Javascript

The Javascript Math object sports a set of built-in methods and constants for performing mathematical calculations in scripts.

Methods of the Math Object

ceil - round a decimal number up to a whole number regardless of decimal value

var num = 5.3;
var result = Math.ceil(num);
document.write(result); // 6


floor - round a decimal number down to a whole number regardless of decimal value

var num = 2.8;
var result = Math.floor(num);
document.write(result); // 2


max - returns the largest number out of a set of numbers

var result = Math.max(3,8,5,2);
document.write(result); // 8


min - returns the smallest number out of a set of numbers

var result = Math.min(600,800,500,900);
document.write(result); // 500


random - returns a random decimal number between "0" and "1"

var result = Math.random();

// 1 - 10 random number (multiply random() by 10, round down and add 1)
var rand_1_thru_10 = Math.floor(Math.random() * 10) + 1;


round - round a decimal number naturally

var num = 7.3;
var result = Math.round(num);
document.write(result); // 7


sqrt - returns the square root of a number

var num = 144;
var result = Math.sqrt(num);
document.write(result); // 12


Trigonometric Methods of the Math Object
abs - returns the distance a number must go to reach 0
acos - returns the arc cosine of a number(number range: -1.0 to 1.0)
asin - returns the arc sine of a number (number range: -1.0 to 1.0)
atan - returns the arctangent of a number
atan2 - returns the arctangent of the quotient of its arguments(Ypoint,Xpoint)
cos - returns the cosine of the number (returns a value between -1 and 1)
log - returns the natural logarithm of a number
pow - returns base number to the exponent power
sin - returns the sine of a number
tan - returns the tangent of a number

var num_abs = Math.abs(aNumber);
var num_acos = Math.acos(aNumber);
var num_asin = Math.asin(aNumber);
var num_atan = Math.atan(aNumber);
var num_atan2 = Math.atan2(Ypoint,Xpoint);
var num_cos = Math.cos(aNumber);
var num_log = Math.log(aNumber);
var num_pow = Math.pow(base,exponent);
var num_sin = Math.sin(aNumber);
var num_tan = Math.tan(aNumber);


Constants(properties) of the Math Object

E - Euler's constant. The base of Natural Logarithms.
LN2 - Natural logarithm of 2
LN10 - Natural logarithm of 10
LOG2E - Base 2 logarithm of E
LOG10E - Base 10 logarithm of E
PI - Ratio of a circle's circumference to its diameter
SQRT1_2 - Square root of 1/2
SQRT2 - Square root of 2

var eul = Math.E; // 2.718281828459045
var ln2 = Math.LN2; // 0.6931471805599453
var ln10 = Math.LN10; // 2.302585092994046
var log2e = Math.LOG2E; // 1.4426950408889634
var log10e = Math.LOG10E; // 0.4342944819032518
var pi = Math.PI; // 3.141592653589793
var sq1_2 = Math.SQRT1_2; // 0.7071067811865476
var sq2 = Math.SQRT2; // 1.4142135623730951


Trigonometric Formulas

Formula for calculating radians:

 radians = degrees * Math.PI/180   

Formula for calculating degrees from radians:

 degrees = radians * 180/Math.PI   


Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2014 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at