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

js operation rounding and string splitting

巴扎黑
巴扎黑Original
2016-12-10 09:13:411201browse

[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 (','))

Statement:
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