Search code examples
javascriptintegerrounding

Javascript - Approximate Number


I was wondering if it is possible to get the approximate number in Javascript? Like if I had a large number for example

var number = 537989;

A bit like the Math.round() , just so it rounds up to 538000. Is there a way to do so? Thanks.


Solution

  • You can write it yourself. Something like

    function myround(number, precision = 1000) {
        var result = Math.round(number / precision) *  precision;
        return result;
    }