1. Discard the decimals and keep the integers
ParseInt (5/2)
2. Round up, add 1 to the whole number if there are decimals
Math. Ceil (5/2)
3. Round.
Math. Round (5/2)
4, round down
Math. Floor (5/2)
Methods of the Math object FF: Firefox, N: Netscape, IE: Internet Explorer
Method describes FF N IE Abs of x returns the absolute value of 1, 2, 3 Acos of x returns the arccosine of the number 1, 2, 3 Asin of x returns the inverse sine of the number 1, 2, 3 Atan of x returns the inverse tangent of x with a value between -pi /2 and PI/2 radians Atan2 (y,x) returns the Angle from the X-axis to the point (x,y) (between -pi /2 and PI/2 radians) 1, 2, 3 Ceil of x rounds up a number. 1 2 3 Cosine of x returns the cosine of 1, 2, 3 Exp of x returns e to the exponent. 1 2 3 Floor of x rounds off a number. 1 2 3 Log of x returns the natural log of the number (base e) 1, 2, 3 Max (x,y) returns the highest value of x and y, 1, 2, 3 Min of x,y returns the lowest values in x and y, 1, 2, 3 Pow of x,y returns x to the y power 1, 2, 3 Random () returns a random number between 0 and 1, 1, 2, 3 Round (x) rounds a number to the nearest integer 1, 2, 3 Sine of x returns the sine of the number 1, 2, 3 SQRT of x returns the square root of 1, 2, 3 Tangent of x returns the tangent of an Angle 1, 2, 3 ToSource () represents the object’s source code 1, 4 - ValueOf () returns the original valueOf a Math object
Code case:
<script type="text/javascript">
// integer
function getResult(num){
return parseInt(num);
}
//Round off the n bits after 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*)$"),"$1")+0;
}
</script>
Other:
var mLength = textMn.length;
var mFirst = parseInt(mLength/60);
// integer
//alert(mLength);
var mLast = mLength; // Take more than
if(mLast>0){
$(".mood_content").height((mFirst+1)*20);
}