public String addUnits ( String value ) { StringBuffer buff = new StringBuffer ( 100 ) ; long bytes = Long . parseLong ( value ) ; if ( bytes < 1000000 ) { buff . append ( value ) ; buff . append ( "B" ) ; } else { int unit = 1000 ; int exp = ( int ) ( Math . log ( bytes ) / Math . log ( unit ) ) ; String pre = "kMGTPE" . charAt ( exp - 1 ) + "" ; String ov = String . format ( "%.1f%sB" , bytes / Math . pow ( unit , exp ) , pre ) ; buff . append ( ov ) ; } return buff . toString ( ) ; }
Utility method to include the SI unit name .