[ACCEPTED]-JavaScript flooring number to order of magnitude-javascript
Accepted answer
So you're looking for the order of magnitude.
function convert(n) {
var order = Math.floor(Math.log(n) / Math.LN10
+ 0.000000001); // because float math sucks like that
return Math.pow(10,order);
}
Simple 4 ^_^ Math is awesome! Floating point imprecisions, however, are 3 not. Note that this won't be completely 2 accurate in certain edge cases, but it will 1 do its best.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.