码迷,mamicode.com
首页 > Windows程序 > 详细

How to add Leading Zeroes to a Number (Delphi Format)

时间:2015-09-07 21:02:41      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

How to add Leading Zeroes to a Number (Delphi Format)

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.

 

How to add Leading Zeroes to a Number (Delphi Format)

标签:

原文地址:http://www.cnblogs.com/shangdawei/p/4789798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!