public static String sayNumber(StringBuffer appendTo,double number) throws IllegalArgumentException {
  if (number == Double.MIN_VALUE) {
    throw new IllegalArgumentException("Out of range");
  }
  if (number < 0) {
    appendTo.append("Minus ");
  }
  double abs=Math.abs(number);
  if (abs < POWER_THREE) {
    saySimpleNumber(appendTo,(int)abs);
  }
 else   if (abs < 2000) {
    int thousand=(int)(abs % POWER_THREE);
    appendTo.append("Seribu ");
    saySimpleNumber(appendTo,thousand);
  }
 else   if (abs < POWER_SIX) {
    int thousand=(int)(abs % POWER_SIX / POWER_THREE);
    saySimpleNumber(appendTo,thousand);
    appendTo.append(" Ribu");
    double remainder=abs - thousand * POWER_THREE;
    if (remainder > 0) {
      appendTo.append(' ');
      sayNumber(appendTo,remainder);
    }
  }
 else   if (abs < POWER_NINE) {
    int million=(int)(abs % POWER_NINE / POWER_SIX);
    saySimpleNumber(appendTo,million);
    appendTo.append(" Juta");
    double remainder=abs - million * POWER_SIX;
    if (remainder > 0) {
      appendTo.append(' ');
      sayNumber(appendTo,remainder);
    }
  }
 else   if (abs < POWER_TWELVE) {
    int billion=(int)(abs % POWER_TWELVE / POWER_NINE);
    saySimpleNumber(appendTo,billion);
    appendTo.append(" Milyar");
    double remainder=abs - billion * POWER_NINE;
    if (remainder > 0) {
      appendTo.append(' ');
      sayNumber(appendTo,remainder);
    }
  }
 else   if (abs < POWER_FIFTEEN) {
    int trillion=(int)(abs % POWER_FIFTEEN / POWER_TWELVE);
    saySimpleNumber(appendTo,trillion);
    appendTo.append(" Trilyun");
    double remainder=abs - trillion * POWER_TWELVE;
    if (remainder > 0) {
      appendTo.append(' ');
      sayNumber(appendTo,remainder);
    }
  }
 else {
    appendTo.append("Lebih Dari Seribu Triliun");
  }
  return appendTo.toString();
}

public static String sayNumber ( StringBuffer appendTo , double number ) throws IllegalArgumentException { if ( number == Double . MIN_VALUE ) { throw new IllegalArgumentException ( "Out of range" ) ; } if ( number < 0 ) { appendTo . append ( "Minus " ) ; } double abs = Math . abs ( number ) ; if ( abs < POWER_THREE ) { saySimpleNumber ( appendTo , ( int ) abs ) ; } else if ( abs < 2000 ) { int thousand = ( int ) ( abs % POWER_THREE ) ; appendTo . append ( "Seribu " ) ; saySimpleNumber ( appendTo , thousand ) ; } else if ( abs < POWER_SIX ) { int thousand = ( int ) ( abs % POWER_SIX / POWER_THREE ) ; saySimpleNumber ( appendTo , thousand ) ; appendTo . append ( " Ribu" ) ; double remainder = abs - thousand * POWER_THREE ; if ( remainder > 0 ) { appendTo . append ( ' ' ) ; sayNumber ( appendTo , remainder ) ; } } else if ( abs < POWER_NINE ) { int million = ( int ) ( abs % POWER_NINE / POWER_SIX ) ; saySimpleNumber ( appendTo , million ) ; appendTo . append ( " Juta" ) ; double remainder = abs - million * POWER_SIX ; if ( remainder > 0 ) { appendTo . append ( ' ' ) ; sayNumber ( appendTo , remainder ) ; } } else if ( abs < POWER_TWELVE ) { int billion = ( int ) ( abs % POWER_TWELVE / POWER_NINE ) ; saySimpleNumber ( appendTo , billion ) ; appendTo . append ( " Milyar" ) ; double remainder = abs - billion * POWER_NINE ; if ( remainder > 0 ) { appendTo . append ( ' ' ) ; sayNumber ( appendTo , remainder ) ; } } else if ( abs < POWER_FIFTEEN ) { int trillion = ( int ) ( abs % POWER_FIFTEEN / POWER_TWELVE ) ; saySimpleNumber ( appendTo , trillion ) ; appendTo . append ( " Trilyun" ) ; double remainder = abs - trillion * POWER_TWELVE ; if ( remainder > 0 ) { appendTo . append ( ' ' ) ; sayNumber ( appendTo , remainder ) ; } } else { appendTo . append ( "Lebih Dari Seribu Triliun" ) ; } return appendTo . toString ( ) ; }
say a number . this method will append the result to the given string buffer .
