public static String getLocalizedFileSize ( final Context context , double numSize ) { String localeLanguage = Locale . getDefault ( ) . getLanguage ( ) ; if ( ! SIZE_LANGUAGE . equals ( localeLanguage ) && context != null && context . getResources ( ) != null ) { Resources resources = context . getResources ( ) ; SIZE_BYTES = resources . getString ( R . string . boxsdk_bytes ) ; SIZE_KILOBYTES = resources . getString ( R . string . boxsdk_kilobytes ) ; SIZE_MEGABYTES = resources . getString ( R . string . boxsdk_megabytes ) ; SIZE_GIGABYTES = resources . getString ( R . string . boxsdk_gigabytes ) ; SIZE_TERABYTES = resources . getString ( R . string . boxsdk_terabytes ) ; SIZE_LANGUAGE = localeLanguage ; } String textSize = null ; double size ; if ( numSize < constKB ) { textSize = String . format ( Locale . getDefault ( ) , SIZE_BYTES , numSize ) ; } else if ( ( numSize >= constKB ) && ( numSize < constMB ) ) { size = numSize / floatKB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_KILOBYTES , size ) ; } else if ( ( numSize >= constMB ) && ( numSize < constGB ) ) { size = numSize / floatMB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_MEGABYTES , size ) ; } else if ( numSize >= constGB && ( numSize < constTB ) ) { size = numSize / floatGB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_GIGABYTES , size ) ; } else if ( numSize >= constTB ) { size = numSize / floatTB ; textSize = String . format ( Locale . getDefault ( ) , SIZE_TERABYTES , size ) ; } return textSize ; }
Java version of routine to turn a long into a short user readable string .