public StringBuffer format(double number, StringBuffer dest, FieldPosition fieldPos) {  if (Double.isNaN(number)) { dest.append(symbols.getNaN()); if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD) { int index = dest.length(); fieldPos.setBeginIndex(index - symbols.getNaN().length()); fieldPos.setEndIndex(index); } return dest; }  boolean is_neg = number < 0; if (is_neg) { if (negativePrefix != null) dest.append(negativePrefix); else { dest.append(symbols.getMinusSign()); dest.append(positivePrefix); } number = -number; } else dest.append(positivePrefix);  int integerBeginIndex = dest.length(); int integerEndIndex = 0; if (Double.isInfinite(number)) { dest.append(symbols.getInfinity()); integerEndIndex = dest.length(); } else { number *= multiplier;   long exponent = 0; double baseNumber; if (useExponentialNotation) { exponent = (long) Math.floor(Math.log(number) / Math.log(10)); if (minimumIntegerDigits > 0) exponent -= minimumIntegerDigits - 1; baseNumber = (long) (number / Math.pow(10.0, exponent)); } else baseNumber = number;   baseNumber += 5 * Math.pow(10.0, -maximumFractionDigits - 1);  int index = dest.length(); double intPart = Math.floor(baseNumber); int count = 0; while (count < maximumIntegerDigits && (intPart > 0 || count < minimumIntegerDigits)) { long dig = (long) (intPart % 10); intPart = Math.floor(intPart / 10);   if (groupingUsed && count > 0 && count % groupingSize == 0) dest.insert(index, symbols.getGroupingSeparator());  dest.insert(index, (char) (symbols.getZeroDigit() + dig));  ++count; }  integerEndIndex = dest.length();  int decimal_index = integerEndIndex; int consecutive_zeros = 0; int total_digits = 0;   double fracPart = baseNumber - Math.floor(baseNumber); for (count = 0; count < maximumFractionDigits && (fracPart != 0 || count < minimumFractionDigits); ++count) { ++total_digits; fracPart *= 10; long dig = (long) fracPart; if (dig == 0) ++consecutive_zeros; else consecutive_zeros = 0; dest.append((char) (symbols.getZeroDigit() + dig));   fracPart = fracPart - Math.floor(fracPart); }    int extra_zeros = Math.min(consecutive_zeros, total_digits - minimumFractionDigits); if (extra_zeros > 0) { dest.setLength(dest.length() - extra_zeros); total_digits -= extra_zeros; }   if (decimalSeparatorAlwaysShown || total_digits > 0) { dest.insert(decimal_index, symbols.getDecimalSeparator()); if (fieldPos != null && fieldPos.getField() == FRACTION_FIELD) { fieldPos.setBeginIndex(decimal_index + 1); fieldPos.setEndIndex(dest.length()); } }   if (useExponentialNotation) { dest.append(symbols.getExponential()); if (exponent < 0) { dest.append(symbols.getMinusSign()); exponent = -exponent; } index = dest.length(); for (count = 0; exponent > 0 || count < minExponentDigits; ++count) { long dig = exponent % 10; exponent /= 10; dest.insert(index, (char) (symbols.getZeroDigit() + dig)); } } }  if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD) { fieldPos.setBeginIndex(integerBeginIndex); fieldPos.setEndIndex(integerEndIndex); }  dest.append((is_neg && negativeSuffix != null) ? negativeSuffix : positiveSuffix);
public StringBuffer format (double number, StringBuffer dest, FieldPosition fieldPos) { formatInternal (number, new StringFormatBuffer(dest), fieldPos);
	public StringBuffer format(double number, StringBuffer dest, FieldPosition fieldPos) {		// A very special case.		if (Double.isNaN(number)) {			dest.append(symbols.getNaN());			if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD) {				int index = dest.length();				fieldPos.setBeginIndex(index - symbols.getNaN().length());				fieldPos.setEndIndex(index);			}			return dest;		}		boolean is_neg = number < 0;		if (is_neg) {			if (negativePrefix != null)				dest.append(negativePrefix);			else {				dest.append(symbols.getMinusSign());				dest.append(positivePrefix);			}			number = -number;		} else			dest.append(positivePrefix);		int integerBeginIndex = dest.length();		int integerEndIndex = 0;		if (Double.isInfinite(number)) {			dest.append(symbols.getInfinity());			integerEndIndex = dest.length();		} else {			number *= multiplier;			// Compute exponent.			long exponent = 0;			double baseNumber;			if (useExponentialNotation) {				exponent = (long) Math.floor(Math.log(number) / Math.log(10));				if (minimumIntegerDigits > 0)					exponent -= minimumIntegerDigits - 1;				baseNumber = (long) (number / Math.pow(10.0, exponent));			} else				baseNumber = number;			// Round to the correct number of digits.			baseNumber += 5 * Math.pow(10.0, -maximumFractionDigits - 1);			int index = dest.length();			double intPart = Math.floor(baseNumber);			int count = 0;			while (count < maximumIntegerDigits && (intPart > 0 || count < minimumIntegerDigits)) {				long dig = (long) (intPart % 10);				intPart = Math.floor(intPart / 10);				// Append group separator if required.				if (groupingUsed && count > 0 && count % groupingSize == 0)					dest.insert(index, symbols.getGroupingSeparator());				dest.insert(index, (char) (symbols.getZeroDigit() + dig));				++count;			}			integerEndIndex = dest.length();			int decimal_index = integerEndIndex;			int consecutive_zeros = 0;			int total_digits = 0;			// Strip integer part from NUMBER.			double fracPart = baseNumber - Math.floor(baseNumber);			for (count = 0; count < maximumFractionDigits && (fracPart != 0 || count < minimumFractionDigits); ++count) {				++total_digits;				fracPart *= 10;				long dig = (long) fracPart;				if (dig == 0)					++consecutive_zeros;				else					consecutive_zeros = 0;				dest.append((char) (symbols.getZeroDigit() + dig));				// Strip integer part from FRACPART.				fracPart = fracPart - Math.floor(fracPart);			}			// Strip extraneous trailing `0's.  We can't always detect			// these in the loop.			int extra_zeros = Math.min(consecutive_zeros, total_digits - minimumFractionDigits);			if (extra_zeros > 0) {				dest.setLength(dest.length() - extra_zeros);				total_digits -= extra_zeros;			}			// If required, add the decimal symbol.			if (decimalSeparatorAlwaysShown || total_digits > 0) {				dest.insert(decimal_index, symbols.getDecimalSeparator());				if (fieldPos != null && fieldPos.getField() == FRACTION_FIELD) {					fieldPos.setBeginIndex(decimal_index + 1);					fieldPos.setEndIndex(dest.length());				}			}			// Finally, print the exponent.			if (useExponentialNotation) {				dest.append(symbols.getExponential());				if (exponent < 0) {					dest.append(symbols.getMinusSign());					exponent = -exponent;				}				index = dest.length();				for (count = 0; exponent > 0 || count < minExponentDigits; ++count) {					long dig = exponent % 10;					exponent /= 10;					dest.insert(index, (char) (symbols.getZeroDigit() + dig));				}			}		}		if (fieldPos != null && fieldPos.getField() == INTEGER_FIELD) {			fieldPos.setBeginIndex(integerBeginIndex);			fieldPos.setEndIndex(integerEndIndex);		}		dest.append((is_neg && negativeSuffix != null) ? negativeSuffix : positiveSuffix);		return dest;	}