1. Discard the fractional part, preserving the integer part
parseint (23.56);
Results: 23
2. Rounding up, with decimals on the integer part plus 1
Math.ceil (23.56)
Results: 24
3, rounded.
Math.Round (23.56)
Results: 24
4, rounding down
Math.floor (23.56)
Results: 23
Attached: How to determine the type of numeric input (without quotation marks when used!) )
"^\\d+$"//nonnegative 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 + 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
" ^ (-\\d+ (\\.\\d+)?) | (0+ (\\.0+)?)) $ "//non-positive floating point number (negative floating point + 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 //str for the character you want to judge Var str= "23.56"; r.test (str); Executes the returned result true or False
Result: false
5, numerical rounding and taking of decimal parts
var a = "23.56"; var b = A.split ("."); var x=b[0];var y=b[1];
Results: x=23,y=56
Take decimal integer part function in JS and take fractional part