1. Discard the decimal part and keep the integer part
parseInt(5/2)
2. Round upwards, add 1 to the integer part if there is a decimal.
Math.ceil(5/2)
3. Round.
Math.round(5/2)
4. Round downward
Math.floor(5/2)
Methods of Math object
FF: Firefox, N: Netscape, IE: Internet Explorer
Method Description 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 sine value of the number 1 2 3
atan(x) returns the arctangent value of x as a value between -PI/2 and PI/2 radians 1 2 3
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(x) Round up 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) Round down a number. 1 2 3
log(x) Returns the natural logarithm of the number (bottom is 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 of 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 2 3
round(x) rounds a number to the closest 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 an angle 1 2 3
toSource() represents the source code of the object 1 4 -
valueOf() Returns the original value of a Math object
Code case:
The code copy is as follows:
<script type="text/javascript">
//Summarize
function getResult(num){
return parseInt(num);
}
// Round to n bits behind num
function getResult(num,n){
return Math.round(num*Math.pow(10,n))/Math.pow(10,n);
}
//Intercept n bits
function getresult(num,n){
return num.toString().replace(new RegExp("^(//-?//d*//.?//d{0,"+n+"})(//d*)$"),"$1")+0;
}
</script>
other:
The code copy is as follows:
var mLength = textMn.length;
var mFirst = parseInt(mLength/60);
//Summarize
//alert(mLength);
var mLast = mLength; //Take the remainder
if(mLast>0){
$(".mood_content").height((mFirst+1)*20);
}