1. Junior Coders
Join Date
Jul 2007
Posts
34
Thanks
0
Thanked 0 Times in 0 Posts

Hi I need to get the value of a number (-1). If the number has leading zeros they are deleted on output for some reason or another.

Is there a way to preserve any leading zeros that might be present in "number" to be re-outputted in "numberm1"?

Code:
```dim number
dim numberm1

number = "00500"

numberm1 = number - 1

response.write numberm1```
Thanks so much

2. I don't think you can, as in any coding language, the number is stripped of all extraneous stuff like that. Once you have your result, you can format it by adding leading zeros, but you would have to change it back into a string to do so. It started out as a string (because it is quoted), but you changed it into a number as soon as you subtracted 1 from it.

3. Junior Coders
Join Date
Jul 2007
Posts
34
Thanks
0
Thanked 0 Times in 0 Posts

I found this code but I'm just not sure how to use it to automate how many zeros there were to begin with on output.

Code:
```NumberOfLeadingZeros = 3
MyNumber = 18

4. I don't know enough asp or VB off hand to tell you. I could probably look it up. It's tricky though, say your number as a string was "00100" - what would you want the result to be? Would it be:

00099

or:

0099

?

If the second one is acceptable and you know how many leading zeros, you could just do:

Code:
```response.write "00"
response.write numberm1```

5. Junior Coders
Join Date
Jul 2007
Posts
34
Thanks
0
Thanked 0 Times in 0 Posts
Thanks John. Yeah the second one is exactly what I need but the problem is I have absolutely no idea how many leading zeros there might be in the string (or if there would be any at all to begin with).

6. It would be something like:

Code:
```num = "00100"
zeros = ""
do while Left(num, 1) = "0"
num = ltrim(num)
zeros = zeros & "0"
loop
num2 = num - 1
Response.Write(zeroes & num2)```
But I doubt that will work as my syntax is wrong, but I hope you get the idea.
Last edited by jscheuer1; 02-01-2009 at 12:24 PM. Reason: add disclaimer

7. Junior Coders
Join Date
Jul 2007
Posts
34
Thanks
0
Thanked 0 Times in 0 Posts
Thanks so much for the leg up, that really helps my confusion on the situation.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•