# Bytes to Readable format (bytes, kb, mb etc)

**URL:** <https://forum.kirupa.com/t/bytes-to-readable-format-bytes-kb-mb-etc/306523>\
**Category:** open source\
**Created:** [March 16, 2010, 11:27pm UTC](https://forum.kirupa.com/t/bytes-to-readable-format-bytes-kb-mb-etc/306523 "2010-03-16T23:27:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [March 16, 2010, 11:27pm UTC](https://forum.kirupa.com/t/bytes-to-readable-format-bytes-kb-mb-etc/306523/1 "2010-03-16T23:27:49Z")

</div>

I thought this might come in handy for some people needing to convert bytes to a readable format. For example, I am making an uploader. This formats the bytes for you.

```php

public static function readablizeBytes(bytes:uint):String
{
	var s:Array = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
	var e:Number = Math.floor( Math.log( bytes ) / Math.log( 1024 ) );
	return ( bytes / Math.pow( 1024, Math.floor( e ) ) ).toFixed( 2 ) + " " + s[e];
}

trace(readablizeBytes(50964241)); // 48.60 MB

```
