Menu

#391 format-number() applied to integer: too few leading zeroes

v8.5
closed
5
2012-10-08
2005-08-14
Michael Kay
No

When the argument of format-number is an integer, and
leading zeroes are required, too few leading zeroes are
added. For example, the result of format-number(1,
'00000') is "001".

The problem was reported on Saxon 8.5 but has been
present for a number of earlier releases.

Source fix: in
net.sf.saxon.functions.FormatNumber2.java, at line 621,
change:

for (int i=0; i < minWholePartSize - sb.length(); i++) {
sb.insert(0, '0');
}

to

int leadingZeroes = minWholePartSize - sb.length();
for (int i=0; i < leadingZeroes; i++) {
sb.insert(0, '0');
}

Michael Kay

Discussion