JS up rounding, down rounding, rounding createtime--2018 April 14 11:31:21author:marydon
//1. Keep only the integer part (discard fractional part)parseint (5.1234);//5//2. Rounding Down (<= the largest integer of the number) and parseint ()Math.floor (5.1234);//5//3. Rounding up (with decimals, integers + 1)Math.ceil (5.1234);//4. Rounding (number of decimal parts)Math.Round (5.1234);//5Math.Round (5.6789);//6//5. Absolute valueMath.Abs (-1);//1//6. Return a larger value in both(Math.max);//2//7. Return the smaller values in both(math.min);//1//random Number (0-1)Math.random ();
About Math.floor () and parseint ()
All two of them are reserved integers only, but may be inaccurate when converted:
Tipping point:
When there are 16 decimal places, and the last decimal is 5 o'clock, the value is the largest integer of the number;
Math.floor (5.9999999999999995);//5
When there are 16 decimal places, and the last decimal is 6 o'clock, the value is the largest integer +1 of the number.
Math.floor (5.9999999999999996);//6
Related recommendations:
Similar articles
JS rounding up, rounding down