js arrotondare superiore numero code example
Example 1: js arrotondare superiore numero
function roundTo(value, places){
var power = Math.pow(10, places);
return Math.round(value * power) / power;
}
var myNum = 10000/3;
roundTo(myNum, 2);
roundTo(myNum, 0);
roundTo(myNum, -2);
Example 2: js arrotondare superiore numero
function ceilTo(value, places){
var power = Math.pow(10, places);
return Math.ceil(value * power) / power;
}
function floorTo(value, places){
var power = Math.pow(10, places);
return Math.floor(value * power) / power;
}
Example 3: js arrotondare superiore numero
var myNum = 2/3;
var multiplier = 100;
var a = Math.round(myNum * multiplier) / multiplier;
var b = Math.ceil (myNum * multiplier) / multiplier;
var c = Math.floor(myNum * multiplier) / multiplier;
Example 4: js arrotondare superiore numero
var c = Math.round(-2.7);
var c = Math.round(-2.5);
Example 5: js arrotondare superiore numero
var myNum = 10000/3;
var multiplier = 1/100;
var a = Math.round(myNum * multiplier) / multiplier;
var b = Math.ceil (myNum * multiplier) / multiplier;
var c = Math.floor(myNum * multiplier) / multiplier;
Example 6: js arrotondare superiore numero
Math.trunc(2.3);
Math.trunc(-2.3);
Math.trunc(2147483648.1);
Math.trunc(-2147483649.1);
Math.trunc(NaN);
Example 7: js arrotondare superiore numero
var a = Math.ceil(2.3);
var b = Math.ceil(2.7);