The Delphi Bug List

Entry No.
371
RTL - Sys - SysUtils - Format
Using the FORMAT statement with an integer specifier larger than 15 (ie: '%.16d' ) does not pad with zeros as expected.
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
ExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExistsExists
Description
Reported by Ken Henke; checked by Reinier Sterkenburg
In the past I've accomplished zero-padding by using the FORMAT statement like so:
  nTemp:= 3;
  sTemp:= Format('%.6d', [nTemp])
  {sTemp now equals '000003'}
But, when I tried to do that on a field with 16 digits, it seems to ignore the specifier. For example:
  nTemp:= 3;
  sTemp:= Format('%.16d', [nTemp])
  {sTemp now equals '3' instead of '0000000000000003'}
This is a bug because the FORMAT specifier '%.16d' should be padding with zeros. There isn't a documented reason why this shouldn't work on specifiers larger than 15.

Borland's Chuck Jazdzewski commented on this (26 Feb 99):
This is a documentation bug. Ordinals of 32 bits or less are limited to 16 digits of precision. Int64 gets 32 digits.

Miken Bean pointed out that (28 Feb 2000):
This bug has not been fully fixed in version 5.0 as listed on the web site. The format function works correctly for a format specifier of "%.16d" however, if fails as soon as the precision specifier reaches 17. Chuck Jazdzewski comment that one should use Int64 to get 32 digits of precision does not seem to work.

RS, 10 June 2001:
Miken Bean's remark is accurate; under Delphi 5.01 as well as under Kylix

Solution / workaround
Use other string-functions to achieve the desired effect.
Latest update of this entry: 2002-04-03

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.