Rounding Reference
by carlinmack
HTML
<div id="console-log"></div>
JavaScript
var consoleLine = "<p class=\"console-line\"></p>";
console = {
log: function (text) {
$("#console-log").append($(consoleLine).html(text));
}
};
//Math.floor rounds to the bottom value, example
console.log("Floor = " + Math.floor(34.99999)); //= 34
//Math.ceil rounds to the upper value, example
console.log("Ceiling = "+ Math.ceil(34.00001)); //= 35
//Math.round rounds to the nearest decimal place, example
console.log("Round = " + Math.round(34.499999)); //= 34
console.log("Round = " + Math.round(34.5)); //= 35
//To round to a certain decimal place, just multiply and divide the number
//this is easier done than explained
//take this code for example
Math.round(34.499999);
//If we wanted to round to one decimal place instead, we would simply
//times by ten, to get the first decimal above the point,
//then round, and then divide by ten to get the original format, example
console.log("To one decimal place = " + Math.round(34.499999*10)/10); //= 34.5