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

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.

时间: 2025-01-02 16:15:24

How to add Leading Zeroes to a Number (Delphi Format)的相关文章

解决导出Excel时提示“Warning: Maximum number of format records exceeded. Using default format”

最近在使用jxl导出Excel文件时出现一个问题,就是当数据量比较多的时候,后天会提示" Warning:  Maximum number of format records exceeded.  Using default format",然后导出的Excel文件打开后会报错,导出失败.解决方案是更换一下jar包. 下载地址:

Educational Codeforces Round 7 B

Description You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes. Note that you should find only the time after a minutes, see the examples to clarify the problem statement. You can read more about 24-hour f

uva 10012 How Big Is It?(枚举)

uva 10012 How Big Is It? Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom o

POJ 3301 Texas Trip

题目链接:http://poj.org/problem?id=3301 Texas Trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4935 Accepted: 1543 Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The

poj 3301 Texas Trip(几何+三分)

Description After a day trip with his friend Dick, Harry noticed a strange pattern of tiny holes in the door of his SUV. The local American Tire store sells fiberglass patching material only in square sheets. What is the smallest patch that Harry nee

UVA How Big Is It? (DFS+回溯)

 How Big Is It?  Ian's going to California, and he has to pack his things, including his collection of circles. Given a set of circles, your program must find the smallest rectangular box in which they fit. All circles must touch the bottom of the bo

CSCI3180 – Principles of Programming Languages

CSCI3180 – Principles of Programming Languages – Spring 2019Assignment 1 - Human Resources Management System in FORTRAN and COBOLDeadline: Feb 03, 2019 (Sunday) 23:591 IntroductionIn this assignment, you have to implement a system for processing empl

[Algorithm] 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0] Note: You must do this in-place without making a copy of the array

445 Add Two Numbers II

You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not con