This article describes the details of functions that take the fractional integer part in JavaScript advanced (5) js. If you want to use this function, you can refer to the following JavaScript to take the fractional integer part. The function discards the fractional part and retains the integer part.
Js: parseInt (7/2)
Rounded up. If there is a decimal number, add 1 to the integer.
Js: Math. ceil (7/2)
Rounding
Js: Math. round (7/2)
Round down
Js: Math. floor (7/2)
Appendix: how to determine the type of the input value (without quotation marks !)
The regular expression is used.
"^ \ D + $" // non-negative integer (positive integer + 0)
"^ [0-9] * [1-9] [0-9] * $" // positive integer
"^ (-\ D +) | (0 +) $" // non-positive integer (negative integer + 0)
"^-[0-9] * [1-9] [0-9] * $" // negative integer
"^ -? \ D + $ "// integer
"^ \ D + (\. \ d + )? $ "// Non-negative floating point number (Positive floating point number + 0)
"^ ([0-9] + \\. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// Positive floating point number
"^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ "// Non-Positive floating point number (negative floating point number + 0)
"^ (-([0-9] + \\. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// negative floating point number
"^ (-? \ D +) (\. \ d + )? $ "// Floating point number
Example
Var r =/^ [0-9] * [1-9] [0-9] * $ // positive integer
R. test (str); // str returns true or false for the characters to be judged.
Meiwenmeitu
The above is the content. For more information, please follow the PHP Chinese Network (www.php1.cn )!