Home > Article > Web Front-end > js operation rounding and string splitting
[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
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 (','))