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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill in leading zero

Status
Not open for further replies.

culleoka

Programmer
May 16, 2002
85
US
I have a char field in a table called price.

I need to replace the price with str(val(price, , )) with leading zeroes in the price, but cannot find the command to use.

I hate to ask a question I KNOW has been asked before(and recently), but after going through pages 1 to 27 on this site, searching MSDN and VFP 5 Help, I haven't been able to find it. And the Keyword Search facility on this site is down right now.

Must be in my wording.

Any help out there?

Pat

 
this is a statement I use to put the field empe_cont into a character field with leading zeroes.

replace c_empecont WITH STRTRAN(STR(empe_cont,8),' ','0')

Betty

 
You can also use padl() or padr() or padc() to "pad" a string with a character:

eg:
empe_cont=2.34

?padl(alltr(str(empe_cont,8,2)), 8, "0")="00002.34"
 
Pat,

if you really want to do it programatically you can use a routine like this:

yiv=your_input_variable
l=len(your_input_variable)
x=len(the_desired_length_of_your_field) && (tdloyf)

do while l<=x
tdloyf=&quot;0&quot;+yiv
endo

this would bring up &quot;123&quot; to any match_lengt you want with &quot;0123&quot;, &quot;00123&quot;, &quot;000123&quot;, ....


wilfredo
 
I use this ...


* DOC BEGIN
*
* function zerostr(nInteger,nLen)
* Returns the integer as a string.
* Zeros are attached to front to attain proper length.
*
* DOC END
function zerostr(nInteger,nLen)
local cInteger,nParams
nParams = parameters()
cInteger = alltrim(str(nInteger,20))
if nParams = 2
do while len(cInteger) < nLen
cInteger = &quot;0&quot;+cInteger
enddo
endif
return cInteger
Don
dond@csrinc.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top