In JavaScript, I may have a random number generated, that may be 3,123, or 3,001, or 2790, etc.. Which JavaScript method will help me out in returning a target whole integer because these values…
3,123, or 3,001, or 2790 are closer to 3000, rather than 4000 or 2000, or 1000.
Thanks for any advice.
Try:
If
rand_numis 3123, 3001 or 2790, it will be reduced to either 3.123, 3.001 and 2.729 respectively, rounded to 3.0 and multiplied to become 3000.