Reputation: 811
I have to round down any values to multiples of 1000.
Example 1,
var myValue = 23452;
Math.round(myValue/1000)*1000;
23000
Example 2,
var myValue = 22745;
Math.round(myValue/1000)*1000;
23000
In above cases example 1 is giving expected round down value as 23000, however example 2, I'm expecting 22000
how to achieve any values to always round down to multiples to 1000. more examples,
if 6700 then 6000
if 17500 then 17000
if 356242 then 350000
if 600 then 0
Upvotes: 0
Views: 129
Reputation: 1846
Enter the Modulus operator.
var myValue = 22745;
var remainder = myValue % 1000; //745
var myRoundedValue = myValue - remainder; //22000
Upvotes: 6