Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4610

Friendly Byte Formatting in Rails

$
0
0

I need to format an integer representation of bytes into something friendly, and I'm hoping that there's a utility function in Ruby or in Rails that will do that formatting for me (to perpetuate my laziness, of course.)

I'm looking for something that would look like:

format_bytes(1024)     -> "1 KB"format_bytes(1048576)  -> "1 MB"

Looks like there's some stuff in ActiveSupport to do it the other way around, but I haven't found a way to do it in this direction.

If there isn't one that exists, does anyone have a particularly elegant solution?


Viewing all articles
Browse latest Browse all 4610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>