how to round 17000595 to 17000500 with javascript?
Asked
Active
Viewed 2,882 times
1 Answers
13
Here is the formula
- Divide it by 500,
- take its floor value
- and multiply it by 500 again.
code is -
Math.floor(17000595/500) * 500

gurvinder372
- 66,980
- 10
- 72
- 94
-
thanks a bunch it woks! – Devisy Feb 09 '16 at 07:23
-
2Text says 'ceiling', code says `floor`, and maybe you could consider using `Math.round`, if you want, for example, 800 to be rounded up to 1000. – GolezTrol Feb 09 '16 at 07:26
-
clearly floor is right if you look at the example in the question – Jaromanda X Feb 09 '16 at 07:31
-
@goleztrol corrected the formula description, Thanks for pointing out. – gurvinder372 Feb 09 '16 at 08:08
-
hello gurvinder & all can u help me also in how to do it with mysql query? – Devisy Feb 09 '16 at 11:33
-
@DeviSiscaYulita I don't know how to do it. Also, it is not part of your OP. Kindly ask a separate question for the same. – gurvinder372 Feb 09 '16 at 13:33
-
it's good to use Math.ceil instead of floor in floor if you try to run Math.floor(500.5/500) * 500; this you will get 500 which is wrong but ceil will give 1000 Math.ceil(500.5/500) * 500; – VISHNU May 08 '18 at 08:11