3

I am trying to round a number in JavaScript to match the following Excel style rounding.

Excel:

=ROUND(123456,-1)

which outputs

123460

How can I get JavaScript to round to negative decimal places?

dibs
  • 1,018
  • 2
  • 23
  • 35

2 Answers2

5
function round(x, places)
{
    var shift = Math.pow(10, places);
    return Math.round(x * shift) / shift;
}
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
0

Formula.js implements all Math functions offered by Microsoft Excel 2013, including ROUND.

Ismael Ghalimi
  • 3,515
  • 2
  • 22
  • 25