Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Always round down to multiples of 1000

I have to round down any values to multiples of 1000.

Example 1,

var myValue = 23452;
Math.round(myValue/1000)*1000; 
23000

Example 2,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Enter the Modulus operator.

var myValue = 22745;
var remainder = myValue % 1000; //745
var myRoundedValue = myValue - remainder; //22000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading