Round money to nearest 10 dollars in Javascript Round money to nearest 10 dollars in Javascript javascript javascript

Round money to nearest 10 dollars in Javascript


Use this function:

function roundTen(number){  return Math.round(number/10)*10;}alert(roundTen(2823.66));


To round a number to the nearest 10, first divide it by 10, then round it to the nearest 1, then multiply it by 10 again:

val = Math.round(val/10)*10;

This page has some details. They go the other way (e.g., rounding to the nearest 0.01) but the theory and practice are identical - multiply (or divide), round, then divide (or multiply).