public static String formatNumber(float number,int digitCount,boolean separateThousands,char separateChar){
  char[] out=new char[35];
  boolean neg=false;
  if (number == 0) {
    return "0";
  }
  boolean zero=false;
  if (number < 1 && number > -1) {
    zero=true;
  }
  if (number < 0) {
    neg=true;
    number=-number;
  }
  if (digitCount > POW_10.length) {
    digitCount=POW_10.length - 1;
  }
  number*=POW_10[digitCount];
  long lval=Math.round(number);
  int ind=out.length - 1;
  int charCount=0;
  boolean decimalPointAdded=false;
  while (lval != 0 || charCount < (digitCount + 1)) {
    int digit=(int)(lval % 10);
    lval=lval / 10;
    out[ind--]=(char)(digit + '0');
    charCount++;
    if (charCount == digitCount) {
      out[ind--]=',';
      charCount++;
      decimalPointAdded=true;
    }
 else     if (separateThousands && lval != 0 && charCount > digitCount) {
      if (decimalPointAdded) {
        if ((charCount - digitCount) % 4 == 0) {
          out[ind--]=separateChar;
          charCount++;
        }
      }
 else {
        if ((charCount - digitCount) % 4 == 3) {
          out[ind--]=separateChar;
          charCount++;
        }
      }
    }
  }
  if (zero) {
    out[ind--]='0';
    charCount+=1;
  }
  if (neg) {
    out[ind--]='-';
    charCount+=1;
  }
  int start=out.length - charCount;
  return String.valueOf(out,start,out.length - start);
}

public static String formatNumber ( float number , int digitCount , boolean separateThousands , char separateChar ) { char [ ] out = new char [ 35 ] ; boolean neg = false ; if ( number == 0 ) { return "0" ; } boolean zero = false ; if ( number < 1 && number > - 1 ) { zero = true ; } if ( number < 0 ) { neg = true ; number = - number ; } if ( digitCount > POW_10 . length ) { digitCount = POW_10 . length - 1 ; } number *= POW_10 [ digitCount ] ; long lval = Math . round ( number ) ; int ind = out . length - 1 ; int charCount = 0 ; boolean decimalPointAdded = false ; while ( lval != 0 || charCount < ( digitCount + 1 ) ) { int digit = ( int ) ( lval % 10 ) ; lval = lval / 10 ; out [ ind -- ] = ( char ) ( digit + '0' ) ; charCount ++ ; if ( charCount == digitCount ) { out [ ind -- ] = ',' ; charCount ++ ; decimalPointAdded = true ; } else if ( separateThousands && lval != 0 && charCount > digitCount ) { if ( decimalPointAdded ) { if ( ( charCount - digitCount ) % 4 == 0 ) { out [ ind -- ] = separateChar ; charCount ++ ; } } else { if ( ( charCount - digitCount ) % 4 == 3 ) { out [ ind -- ] = separateChar ; charCount ++ ; } } } } if ( zero ) { out [ ind -- ] = '0' ; charCount += 1 ; } if ( neg ) { out [ ind -- ] = '-' ; charCount += 1 ; } int start = out . length - charCount ; return String . valueOf ( out , start , out . length - start ) ; }
formats the given number to the given number of decimals , and returns the number as a string , maximum 35 characters .
