Skip to content

Commit 15bd753

Browse files
committed
[bugfix] Ensure that negative exponents are correctly padded in fn:format-number
1 parent b8c3bb8 commit 15bd753

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FnFormatNumbers.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,22 @@ private String format(final NumericValue number, final DecimalFormat decimalForm
722722
if (minimumExponentSize > 0) {
723723
formatted.append(decimalFormat.exponentSeparator);
724724

725+
final boolean negativeExp = exp < 0;
726+
if (negativeExp) {
727+
// negative exponent, make positive
728+
exp *= -1;
729+
}
725730
final CodePointString expStr = new CodePointString(String.valueOf(exp));
726731

727732
final int expPadLen = subPicture.getMinimumExponentSize() - expStr.length();
728733
if (expPadLen > 0) {
729734
expStr.leftPad(decimalFormat.zeroDigit, expPadLen);
730735
}
731736

737+
if (negativeExp) {
738+
// restore the minus sign for the negative exponent in the output
739+
formatted.append('-');
740+
}
732741
formatted.append(expStr);
733742
}
734743

0 commit comments

Comments
 (0)