Seems like unit prefixes should have a standard PHP function. Maybe in the future.

I found this page while looking for a quick unit prefix function. The one by olafurw was voted down, I think because it had unchecked array indexes and /0s. So here it is fixed and readable.

-Should work down to PHP 4.-Not meant for fractions or negatives, so anything less than 1 returns 0.-Not very effective on really really large numbers, but it's easy to add more prefixes.-Doesn't handle non numeric arguments. PHP 7+ can do this: function binaryprefix( int $units, $unit = '' )

In regards to the note about log in base 10 and the round() function. You need to use floor() instead of round() to find out the order of magnitude. That way, you don't have to worry about subtracting 0.5 or whatever.