Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. function bytes( value, precision = 2 ) {
  2. value = Math.abs( value )
  3. var order = Math.round( Math.log2( value ) / 10 )
  4. order = Math.max( 0, Math.min( order, bytes.units.length - 1 ) ) || 0
  5. value = value / Math.pow( 1024, order )
  6. return `${value.toFixed(precision)} ${bytes.units[order]}`
  7. }
  8.  
  9. bytes.units = 'B,KB,MB,GB,TB,PB,EB,ZB,YB'.split(',')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement