How to convert the last 3 digits of the number?

advertisements

How to convert the last 3 digits of the number? Numbers will be bigger then 8000.

For example:

From 249439 to 249000?


You can get the last three digits using the modulus operator %, which (for positive numbers) computes the remainder after integer division; for example, 249439 % 1000 is 439.

So to round down to the nearest thousand, you can just subtract those three digits:

var rounded = original - original % 1000;

(for example, if original is 249439, then rounded will be 249000).