JSFiddle - React, Tailwind, and code Playground
JavaScript
var MathHelper = (function () {
this.round = function (number, numberOfDecimals) {
var aux = Math.pow(10, numberOfDecimals);
return Math.round(number * aux) / aux;
};
this.floor = function (number, numberOfDecimals) {
var aux = Math.pow(10, numberOfDecimals);
return Math.floor(number * aux) / aux;
};
this.ceil = function (number, numberOfDecimals) {
var aux = Math.pow(10, numberOfDecimals);
return Math.ceil(number * aux) / aux;
};
return {
round: round,
floor: floor,
ceil: ceil
}
})();
document.body.innerHTML += "<h2>ToFixed</h2>" + 5.35.toFixed(1) + " " + 15.35.toFixed(1) + " " + 131.35.toFixed(1) + " " + "<br />" + 2.35.toFixed(1) + " " + 1.35.toFixed(1);
document.body.innerHTML += "<h2>MathHelper Round</h2>" + MathHelper.round(5.35, 1) + " " + MathHelper.round(15.35, 1) + " " + MathHelper.round(131.35, 1) + " " + "<br />" + MathHelper.round(2.35, 1) + " " + MathHelper.round(1.35, 1);
document.body.innerHTML += "<h2>MathHelper Floor</h2>" + MathHelper.floor(5.35, 1) + " " + MathHelper.floor(15.35, 1) + " " + MathHelper.floor(131.35, 1) + " " + "<br />" + MathHelper.floor(2.35, 1) + " " + MathHelper.floor(1.35, 1);