question: public static String toUnitbytes ( long bytes ) { if ( bytes < 0 ) { return "? " + GENERAL_UNIT_KILOBYTES ; } long unitValue ; String unitName ; if ( bytes < 0xA00000 ) { unitValue = 0x400 ; unitName = GENERAL_UNIT_KILOBYTES ; } else if ( bytes < 0x280000000L ) { unitValue = 0x100000 ; unitName = GENERAL_UNIT_MEGABYTES ; } else if ( bytes < 0xA0000000000L ) { unitValue = 0x40000000 ; unitName = GENERAL_UNIT_GIGABYTES ; } else { unitValue = 0x10000000000L ; unitName = GENERAL_UNIT_TERABYTES ; } NumberFormat numberFormat ; if ( ( double ) bytes * 100 / unitValue < 99995 ) numberFormat = NUMBER_FORMAT1 ; else numberFormat = NUMBER_FORMAT0 ; try { return numberFormat . format ( ( double ) bytes / unitValue ) + " " + unitName ; } catch ( ArithmeticException ae ) { return "0 " + unitName ; } }
target:  Converts the passed in number of bytes into a byte-size string. Group digits with locale-dependant thousand separator if needed, but with "KB", or "MB" or "GB" or "TB" locale-dependant unit at the end, and a limited precision of 4 significant digits.