static int formatFloat(final char[] out,float val,int digits){
  boolean negative=false;
  if (val == 0) {
    out[0]='0';
    return 1;
  }
  if (val < 0) {
    negative=true;
    val=-val;
  }
  if (digits >= POW10.length) {
    digits=POW10.length - 1;
  }
  val*=POW10[digits];
  long lval=Math.round(val);
  int index=out.length - 1;
  int charCount=0;
  while (lval != 0 || charCount < (digits + 1)) {
    int digit=(int)(lval % 10);
    lval=lval / 10;
    out[index--]=(char)(digit + '0');
    charCount++;
    if (charCount == digits) {
      out[index--]='.';
      charCount++;
    }
  }
  if (negative) {
    out[index]='-';
    charCount++;
  }
  return charCount;
}

static int formatFloat ( final char [ ] out , float val , int digits ) { boolean negative = false ; if ( val == 0 ) { out [ 0 ] = '0' ; return 1 ; } if ( val < 0 ) { negative = true ; val = - val ; } if ( digits >= POW10 . length ) { digits = POW10 . length - 1 ; } val *= POW10 [ digits ] ; long lval = Math . round ( val ) ; int index = out . length - 1 ; int charCount = 0 ; while ( lval != 0 || charCount < ( digits + 1 ) ) { int digit = ( int ) ( lval % 10 ) ; lval = lval / 10 ; out [ index -- ] = ( char ) ( digit + '0' ) ; charCount ++ ; if ( charCount == digits ) { out [ index -- ] = '.' ; charCount ++ ; } } if ( negative ) { out [ index ] = '-' ; charCount ++ ; } return charCount ; }
formats a float value to the given number of decimals . returns the length of the string . the string begins at out . length - [ return value ] .
