public static String format(long value,int decimalPlaces,boolean base2){
  NumberFormat nf=NumberFormat.getInstance();
  nf.setMinimumFractionDigits(decimalPlaces);
  double doubleResult;
  String unit=base2 ? UNIT_BASE : "";
  double multiplierKilo=multiplier(PREFIX_KILO,base2);
  double multiplierMega=multiplier(PREFIX_MEGA,base2);
  double multiplierGiga=multiplier(PREFIX_GIGA,base2);
  double multiplierTera=multiplier(PREFIX_TERA,base2);
  double multiplierPeta=multiplier(PREFIX_PETA,base2);
  if (value < multiplierKilo) {
    doubleResult=value;
    nf.setMinimumFractionDigits(0);
  }
 else   if (value >= multiplierKilo && value < multiplierMega) {
    doubleResult=round(value / multiplierKilo,decimalPlaces);
    unit=PREFIX_KILO + unit;
  }
 else   if (value >= multiplierMega && value < multiplierGiga) {
    doubleResult=round(value / multiplierMega,decimalPlaces);
    unit=PREFIX_MEGA + unit;
  }
 else   if (value >= multiplierGiga && value < multiplierTera) {
    doubleResult=round(value / multiplierGiga,decimalPlaces);
    unit=PREFIX_GIGA + unit;
  }
 else   if (value >= multiplierTera && value < multiplierPeta) {
    doubleResult=round(value / multiplierTera,decimalPlaces);
    unit=PREFIX_TERA + unit;
  }
 else {
    doubleResult=round(value / multiplierPeta,decimalPlaces);
    unit=PREFIX_PETA + unit;
  }
  return nf.format(doubleResult) + (base2 ? " " : "") + unit;
}

public static String format ( long value , int decimalPlaces , boolean base2 ) { NumberFormat nf = NumberFormat . getInstance ( ) ; nf . setMinimumFractionDigits ( decimalPlaces ) ; double doubleResult ; String unit = base2 ? UNIT_BASE : "" ; double multiplierKilo = multiplier ( PREFIX_KILO , base2 ) ; double multiplierMega = multiplier ( PREFIX_MEGA , base2 ) ; double multiplierGiga = multiplier ( PREFIX_GIGA , base2 ) ; double multiplierTera = multiplier ( PREFIX_TERA , base2 ) ; double multiplierPeta = multiplier ( PREFIX_PETA , base2 ) ; if ( value < multiplierKilo ) { doubleResult = value ; nf . setMinimumFractionDigits ( 0 ) ; } else if ( value >= multiplierKilo && value < multiplierMega ) { doubleResult = round ( value / multiplierKilo , decimalPlaces ) ; unit = PREFIX_KILO + unit ; } else if ( value >= multiplierMega && value < multiplierGiga ) { doubleResult = round ( value / multiplierMega , decimalPlaces ) ; unit = PREFIX_MEGA + unit ; } else if ( value >= multiplierGiga && value < multiplierTera ) { doubleResult = round ( value / multiplierGiga , decimalPlaces ) ; unit = PREFIX_GIGA + unit ; } else if ( value >= multiplierTera && value < multiplierPeta ) { doubleResult = round ( value / multiplierTera , decimalPlaces ) ; unit = PREFIX_TERA + unit ; } else { doubleResult = round ( value / multiplierPeta , decimalPlaces ) ; unit = PREFIX_PETA + unit ; } return nf . format ( doubleResult ) + ( base2 ? " " : "" ) + unit ; }
formats the value as an expression .
