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

digits() question

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
the following expression produces '003':
digits(dec('3',3,0))

The following expression produces '0004':
digits(dec('3',3,0)+1)

Can anyone tell me why it wasn't '004'?

Now I can get '004' with the following:
digits(dec(dec('3',3,0)+1,3,0))

but now we're getting a little rediculous. I guess the real question: Is there any way to increment a decimal without changing it width and scale?
 
Hi,

I would guess that the length is increased to allow for arithmetic overflow, so that adding 1 to a dec(3,0) containg 999 could be shown as 1000.

Brian
 
OK, my goal is to increment a 3 digit numeric text field that is left padded with zeros.

As I mentioned, digits(dec(MyTextField,3,0)+1) does not work because it adds an extra digit.

One solution: digits(dec(dec(MyTextField,3,0)+1,3,0))
Another solution: substr(digits(dec(MyTextField,3,0)+1),2)
Another solution: substr(char(dec(MyTextField,3,0)+1001),2)
Another solution: substr(char(int(MyTextField)+1001),2)

Anyone have an oppinion as to which solution is best? Does anyone have any other approaches?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top