1. Discard the fractional part and keep the whole number of parts
parseint (5/2)
2. Take up the whole, there are decimal numbers on the whole part plus 1
Math.ceil (5/2)
3, rounded.
Math.Round (5/2)
4, take the whole down.
Math.floor (5/2)
Methods of the Math object
Ff:firefox, N:netscape, Ie:internet Explorer
method to describe FF N IE
ABS (x) returns the absolute value of the number 1 2 3
ACOs (x) returns the inverse cosine value of the number 1 2 3
ASIN (x) returns the inverse string value of the number 1 2 3
Atan (x) returns the tangent value of X to 1 2 3, with a value between-PI/2 and PI/2 radians
ATAN2 (y,x) returns the angle (between-PI/2 and PI/2 radians) from the X axis to point (x,y) 1 2 3
Ceil (x) rounds a number. 1 2 3
COS (x) returns the cosine of the number 1 2 3
EXP (x) returns the exponent of E. 1 2 3
Floor (x) rounds a number down. 1 2 3
Log (x) returns the natural logarithm of the number (bottom e) 1 2 3
Max (X,y) returns the highest value in X and y 1 2 3
MIN (x,y) returns the lowest value in X and y 1 2 3
POW (x,y) returns the y power of x 1 2 3
Random () returns a random number between 0 ~ 1 1 2 3
Round (x) rounding a number to the nearest integer 1 2 3
Sin (x) returns the sine of the number 1 2 3
SQRT (x) returns the square root of the number 1 2 3
Tan (x) returns the tangent of a corner 1 2 3
Tosource () represents the object's source code 1 4-
ValueOf () returns the original value of a Math object
Code Case:
Copy Code code as follows:
<script type= "Text/javascript" >
Take the whole
function GetResult (num) {
return parseint (num);
}
Rounding to n digits behind num
function GetResult (num,n) {
Return Math.Round (Num*math.pow (10,n))/math.pow (10,n);
}
Intercept N-bit
function GetResult (num,n) {
Return num.tostring (). Replace (new RegExp ("^ \\-?\\d*\\.? \\d{0, "+n+"}) (\\d*) $ ")," $ "+0;
}
</script>
Other:
Copy Code code as follows:
var mlength = textmn.length;
var Mfirst = parseint (MLENGTH/60);
Take the whole
alert (mlength);
var mlast = mlength; Take more
if (mlast>0) {
$ (". Mood_content"). Height ((mfirst+1) *20);
}