private void setBigDecimalDigits ( String stringDigits , int maximumDigits , boolean fixedPoint ) { //| // Find the first non-zero digit, the decimal, and the last non-zero digit. //| int first=-1, last=stringDigits.length()-1, decimal=-1; //| for (int i=0; (first<0 || decimal<0) && i<=last; ++i) { //| char c = stringDigits.charAt(i); //| if (c == '.') { //| decimal = i; //| } else if (first < 0 && (c >= '1' && c <= '9')) { //| first = i; //| } //| } //| //| if (first < 0) { //| clear(); //| return; //| } //| //| // At this point we know there is at least one non-zero digit, so the //| // following loop is safe. //| for (;;) { //| char c = stringDigits.charAt(last); //| if (c != '0' && c != '.') { //| break; //| } //| --last; //| } //| //| if (decimal < 0) { //| decimal = stringDigits.length(); //| } //| //| count = last - first; //| if (decimal < first || decimal > last) { //| ++count; //| } //| decimalAt = decimal - first; //| if (decimalAt < 0) { //| ++decimalAt; //| } //| //| ensureCapacity(count, 0); //| for (int i = 0; i < count; ++i) { //| digits[i] = (byte) stringDigits.charAt(first++); //| if (first == decimal) { //| ++first; //| } //| } didRound = false ; // The maxDigits here could also be Integer.MAX_VALUE set ( stringDigits , stringDigits . length ( ) ) ; // Eliminate digits beyond maximum digits to be displayed. // Round up if appropriate. // {dlf} Some callers depend on passing '0' to round to mean 'don't round', but // rather than pass that information explicitly, we rely on some magic with maximumDigits // and decimalAt. Unfortunately, this is no good, because there are cases where maximumDigits // is zero and we do want to round, e.g. BigDecimal values -1 < x < 1. So since round // changed to perform rounding when the argument is 0, we now force the argument // to -1 in the situations where it matters. round ( fixedPoint ? ( maximumDigits + decimalAt ) : maximumDigits == 0 ? - 1 : maximumDigits ) ; }
Internal method that sets this digit list to represent the given value . The value is given as a String of the format returned by BigDecimal .