in src/main/java/org/apache/commons/text/numbers/ParsedDecimal.java [710:758]
private String toScientificString(final int decimalPos, final FormatOptions opts) {
final int targetExponent = digitCount + exponent - decimalPos;
final int absTargetExponent = Math.abs(targetExponent);
final boolean includeExponent = shouldIncludeExponent(targetExponent, opts);
final boolean negativeExponent = targetExponent < 0;
// determine the size of the full formatted string, including the number of
// characters needed for the exponent digits
int size = getDigitStringSize(decimalPos, opts);
int exponentDigitCount = 0;
if (includeExponent) {
exponentDigitCount = absTargetExponent > 0
? (int) Math.floor(Math.log10(absTargetExponent)) + 1
: 1;
size += opts.getExponentSeparatorChars().length + exponentDigitCount;
if (negativeExponent) {
++size;
}
}
prepareOutput(size);
// append the portion before the exponent field
final int fractionStartIdx = appendWhole(decimalPos, opts);
appendFraction(0, fractionStartIdx, opts);
if (includeExponent) {
// append the exponent field
append(opts.getExponentSeparatorChars());
if (negativeExponent) {
append(opts.getMinusSign());
}
// append the exponent digits themselves; compute the
// string representation directly and add it to the output
// buffer to avoid the overhead of Integer.toString()
final char[] localizedDigits = opts.getDigits();
int rem = absTargetExponent;
for (int i = size - 1; i >= outputIdx; --i) {
outputChars[i] = localizedDigits[rem % DECIMAL_RADIX];
rem /= DECIMAL_RADIX;
}
outputIdx = size;
}
return outputString();
}