Home > Web Front-end > JS Tutorial > body text

How to take integers and remainders in js_javascript skills

WBOY
Release: 2016-05-16 16:48:55
Original
1825 people have browsed it

1. Discard the decimal part and keep the integer part

parseInt(5/2)

2. Round up, if there is a decimal, add 1 to the integer part

Math.ceil(5/2)

3, rounded up.

Math.round(5/2)

4, round down

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 of the number 1 2 3
asin(x) Returns the inverse of the number Chord value 1 2 3
atan(x) Returns the arctangent of x as a value between -PI/2 and PI/2 radians 1 2 3
atan2(y,x) Returns the value from x Angle from axis to point (x,y) (between -PI/2 and PI/2 radians) 1 2 3
ceil(x) Rounds 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) rounds a number down. 1 2 3
log(x) Returns the natural logarithm of the number (the base is e) 1 2 3
max(x,y) Returns the highest value between x and y 1 2 3
min(x ,y) Returns the lowest value between x and y 1 2 3
pow(x,y) Returns x raised to the y power 1 2 3
random() Returns a random number between 0 ~ 1 1 2 3
round(x) Rounds 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 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 example:

Copy code The code is as follows:


Others:

Copy code The code is as follows:

var mLength = textMn.length;
var mFirst = parseInt(mLength/60);
//Rounding
//alert(mLength);
var mLast = mLength; //Round remainder
if(mLast>0){
$(".mood_content").height((mFirst 1)*20);
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!