Gustavo Sanchez - 1 year ago 62

Javascript Question

I want to round up a number to the nearest thousand, at the moment I'm using this:

`Math.ceil(value/1000)*1000;`

But this goes always up, if I type 1001 it will go to 2000, I want to go up or down depeding on the number, for example 1001 goes to 1000 or 1400 goes to 1000 but 1500 goes to 2000

EDIT:

`if(value<1000){`

value = 1000;

}else{

value = Math.round(value/1000)*1000;

}

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

This will do what you want:

```
Math.round(value/1000)*1000
```

examples:

```
Math.round(1001/1000)*1000
1000
Math.round(1004/1000)*1000
1000
Math.round(1500/1000)*1000
2000
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**