private static void format(StringBuffer target,int scale,long intP,long decP){
  if (decP != 0L) {
    decP+=5L;
    decP/=10L;
    if (decP >= tenPowDouble(scale)) {
      intP++;
      decP-=tenPow(scale);
    }
    if (decP != 0L) {
      while (decP % 10L == 0L) {
        decP=decP / 10L;
        scale--;
      }
    }
  }
  target.append(intP);
  if (decP != 0L) {
    target.append('.');
    while (scale > 0 && (scale > 18 ? decP < tenPowDouble(--scale) : decP < tenPow(--scale))) {
      target.append('0');
    }
    target.append(decP);
  }
}

private static void format ( StringBuffer target , int scale , long intP , long decP ) { if ( decP != 0L ) { decP += 5L ; decP /= 10L ; if ( decP >= tenPowDouble ( scale ) ) { intP ++ ; decP -= tenPow ( scale ) ; } if ( decP != 0L ) { while ( decP % 10L == 0L ) { decP = decP / 10L ; scale -- ; } } } target . append ( intP ) ; if ( decP != 0L ) { target . append ( '.' ) ; while ( scale > 0 && ( scale > 18 ? decP < tenPowDouble ( -- scale ) : decP < tenPow ( -- scale ) ) ) { target . append ( '0' ) ; } target . append ( decP ) ; } }
helper method to do the custom rounding used within formatdoubleprecise
