nzeros = prec - (origPrec - 1);
} else {
compPrec = prec + 1;
}
MathContext mc = new MathContext(compPrec);
BigDecimal v
= new BigDecimal(value.unscaledValue(), scale, mc);
BigDecimalLayout bdl
= new BigDecimalLayout(v.unscaledValue(), v.scale(),
BigDecimalLayoutForm.SCIENTIFIC);
char[] mant = bdl.mantissa();
// Add a decimal point if necessary. The mantissa may not
// contain a decimal point if the scale is zero (the internal
// representation has no fractional part) or the original
// precision is one. Append a decimal point if '#' is set or if
// we require zero padding to get to the requested precision.
if ((origPrec == 1 || !bdl.hasDot())
&& (nzeros > 0 || (f.contains(Flags.ALTERNATE))))
mant = addDot(mant);
// Add trailing zeros in the case precision is greater than
// the number of available digits after the decimal separator.
mant = trailingZeros(mant, nzeros);
char[] exp = bdl.exponent();
int newW = width;
if (width != -1)
newW = adjustWidth(width - exp.length - 1, f, neg);
localizedMagnitude(sb, mant, f, newW, null);
sb.append(f.contains(Flags.UPPERCASE) ? 'E' : 'e');
Flags flags = f.dup().remove(Flags.GROUP);
char sign = exp[0];
assert(sign == '+' || sign == '-');
sb.append(exp[0]);
char[] tmp = new char[exp.length - 1];
System.arraycopy(exp, 1, tmp, 0, exp.length - 1);
sb.append(localizedMagnitude(null, tmp, flags, -1, null));
} else if (c == Conversion.DECIMAL_FLOAT) {
// Create a new BigDecimal with the desired precision.
int prec = (precision == -1 ? 6 : precision);
int scale = value.scale();
if (scale > prec) {
// more "scale" digits than the requested "precision
int compPrec = value.precision();
if (compPrec <= scale) {
// case of 0.xxxxxx
value = value.setScale(prec, RoundingMode.HALF_UP);
} else {
compPrec -= (scale - prec);
value = new BigDecimal(value.unscaledValue(),
scale,
new MathContext(compPrec));
}
}
BigDecimalLayout bdl = new BigDecimalLayout(
value.unscaledValue(),
value.scale(),