Skip to content

Instantly share code, notes, and snippets.

@z2015
Created May 12, 2016 05:46
Show Gist options
  • Save z2015/5e20455d01ece6d3a1a6d9f09156fba6 to your computer and use it in GitHub Desktop.
Save z2015/5e20455d01ece6d3a1a6d9f09156fba6 to your computer and use it in GitHub Desktop.
ceil vs floor vs round

The Math.ceil() function returns the smallest integer greater than or equal to a given number. Math.ceil(.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8

The Math.floor() function returns the largest integer less than or equal to a given number. Math.floor( 45.95); // 45 Math.floor(-45.95); // -46

The Math.round() function returns the value of a number rounded to the nearest integer. // Returns the value 20 x = Math.round(20.49);

// Returns the value 21 x = Math.round(20.5);

// Returns the value -20 x = Math.round(-20.5);

// Returns the value -21 x = Math.round(-20.51);

// Returns the value 1 (!) // Note the rounding error because of inaccurate floating point arithmetics // Compare this with Math.round10(1.005, -2) from the example below x = Math.round(1.005*100)/100;

@Offe1981
Copy link

In the past, vinyl floors remained vulnerable to damage if spills weren't cleaned right away. This has changed due to new developments in luxury vinyl. Spills and pet accidents can be prevented. Accidents happen due to falling on [flooring]([url].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment