js built-in calculation function

// a, Math.round () function: returns an integer rounding. (+0.5 the return parameters, rounded down)
// Math.round (5.57) // returns 6
// Math.round (2.4) // Returns 2
// Math.round (-1.5) // returns -1
// Math.round (-5.8) // return -6

// two, Math.ceil () function: returns the smallest integer greater than or equal parameters.
// Math.ceil (5.57) // returns 6
// Math.ceil (2.4) // Returns 3
// Math.ceil (-1.5) // returns -1
// Math.ceil (-5.8) // returns -5

// three, Math.floor () function: returns the greatest integer less than or equal parameters.
// Math.floor (5.57) // returns 5
// Math.floor (2.4) // Returns 2
// Math.floor (-1.5) // returns -2
// Math.floor (-5.8) // return -6

// four, the parseInt () action: parsing a string, and returns an integer, where the integer can be simply understood as a return parameter of the fractional part discarded.
// parseInt (5.57) // returns 5
// parseInt (2.4) // Returns 2
// parseInt (-1.5) // returns -1
// parseInt (-5.8) // returns -5
// positive number conversion and Math.floor () as a negative number is not the same

// five, Math.random ()
// This method returns a random number ranging between 0 and 1
// If you want to generate a random number to any arbitrary value, the formula is this:
Maximum desired, min - - // // max desired minimum
// parseInt(Math.random()*(max-min+1)+min,10);
// Math.floor(Math.random()*(max-min+1)+min);

Guess you like

Origin www.cnblogs.com/xcj26/p/11294764.html