I have two variables one for decimal numbers and one for integer. Now, i add the decimal numbers with each other and the integers with each other then multiply the sum of decimal numbers and the sum of the integers. My problem now is i want to round them off to the nearest 10 000
So, if 2,54 * 40 000 = 101600 i want my div to display 110 000. Is this possible? I never know what the sum of the decimal numbers or the integers are, i just use two variables
To round a number to the nearest 10,000, check the thousands digit to decide whether to round up or round down. If the thousands are 5000 or more, round up. If they are 4999 or less, round down. 45,000 to the nearest 10,000 is 50,000.
How do you round to the nearest thousandth in Javascript? round(1000*X)/1000; // round X to thousandths To convert a number to a string that represents your number with exactly n decimal places, use the toFixed method.
To round a number up to the nearest 10, call the Math. ceil() function, passing it the number divided by 10 as a parameter and then multiply the result by 10 , e.g. Math. ceil(num / 10) * 10 .
JavaScript Math.round() The Math.round() method rounds a number to the nearest integer. 2.49 will be rounded down (2), and 2.5 will be rounded up (3).
Math.round(101600 / 10000) * 10000 // --> 100000
Math.floor(101600 / 10000) * 10000 // --> 100000
Math.ceil(101600 / 10000) * 10000 // --> 110000
var round = 10000;
var result = round * Math.round(answer / round);
Had to do this recently. Here is a function I wrote to do this automatically.
function getRoundedZeros(value, up){
var roundto = '1';
for(i = 1;i < value.toString().length; i++){
roundto = roundto.concat('0');
}
roundto = parseInt(roundto);
if(up === true){
return Math.ceil(value / roundto) * roundto;
}else{
return Math.floor(value / roundto) * roundto;
}
}
rounded = getRoundedZeros(UNrounded, true);
I hope it helps someone :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With