Home > Web Front-end > JS Tutorial > js operation rounding and string splitting

js operation rounding and string splitting

巴扎黑
Release: 2016-12-06 09:51:22
Original
1069 people have browsed it

[Rounding]
①parseInt (parse the integer, discard the decimal part, keep the integer part)
Syntax: var a =parseInt(5/2);
console.log(a) Output 2

②Math.ceil (take up Integers, if there are decimals, add 1 to the integer part)
Syntax: Math.ceil(5/2) Output 3

③Math.round (rounded)
Syntax: Math.round(5/2) Output 3

④Math.floor( Round down)
Math.floor(5/2) Output 2


[String Splitting]
Method 1: Split the string: string.substring(begin,end) Starting from begin to end, not counting begin
Example:
substring=ITEM000003-2;
for(var i=0;i if(inputs[i].length==10){
items_1.push(inputs[i]) ;
                                                                                                                                                                                                                                                                                                    ; ->From 0 to 10, not counting 0
                                                                                                                                : If an empty string ("") is used as a separator, each character in the stringObject will be split
Example: var ch ='i,like,eat-chicken';
console.log(ch.split (','))

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