Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Integer 1

Status
Not open for further replies.

AP81

Programmer
Apr 11, 2003
740
AU
I am trying to format an integer so that if it is one digit, it includes a leading zero, e.g. 1 becomes 01. The only way I have found to do it is by converting it to a string checking if the length is 1, then adding a 0 to the front.

Is there a better way or a different data type to use?




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
Don't work. No format settings allow to format with leading zero.




------------------------------------
There's no place like 127.0.0.1
------------------------------------
 
d Decimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros."

Format is obscure but powerfull :).

buho (A).
 
I have another way, using FormatFloat. :)

FormatFloat('00', 1) = '01'
 
I hate automatic type conversion.

Passing an integer to a function named "FormatFloat" is "unpascal", no matter what the Borland guys can believe.

:)

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top