Here's how convert (an integer) number to a string by adding an amount of leading zeroes.

Suppose you are developing a database application, and you need to operate on, let's say, a customer number, where each number needs to be exactly 10 digits "long" - but you have customer numbers of 2,4,7, etc. (<10) digits.

The AddLeadingZeroes function accepts two parameters: aNumber is the number that needs to have exactly Length characters (if less, add leading zeroes).

function AddLeadingZeroes(const aNumber, Length : integer) : string;
begin
   result := SysUtils.Format('%.*d', [Length, aNumber]) ;
end;

Usage:

AddLeadingZeroes(2005, 10) ;

Will result in a '0000002005' string value.

 

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-12-19
  • 2021-05-04
  • 2021-09-21
  • 2021-08-07
  • 2021-09-11
猜你喜欢
  • 2021-09-12
  • 2021-09-08
  • 2022-12-23
  • 2021-11-20
  • 2021-07-24
  • 2021-11-28
  • 2021-08-24
相关资源
相似解决方案