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