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

Leading zeros cut off, but needed 1

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
I'm having a problem with some numbers. I need to add zeros to the beginning of three numbers that are input IF those numbers are less than 3 digits. I have that working I believe. I have the numbers stored as strings and add one or two zeros to the beginning of those strings if needed.

Now, after all of that I have to connect those 3 numbers into one larger number that will be 9 digits, and the problem is the first number. If I have to add zeros to the first number, then those zeros get cut off when I string them all together into a large number. So it's the leading zeros that get chopped off, and I was wondering how to avoid that.

I'm sure it's not that tough, but I'm having trouble. Thanks!
 
Ok, sorry I made a mistake there. What I'm doing is taking that string, and making it an integer. THAT's when my zeros are getting cut off. Question still applies, however.
 
When you convert the string

00025125456

to an integer, you will get

25125456

I don't know of anyway to change a string to an integer and not remove the leading zeros because '00025125456' is NOT an integer!

if you need the leading zeros, why do you need to change it to an integer? Do you need to do some calculation to it? Then add the zeros after the calculation.

Unless I'm going to use a number for calculation, I almost always store it as a string (like zipcodes and SSN - what's the use of adding up SSN? plus if you store the SSN as a number and its 081-52-5555, the "number" will be: 8152555; if you store it as a string, it's stored as: 081525555)

Sorry not to be more help!

leslie


 
Ya know, I actually was just asking myself..."self, why does it have to be an integer?" and I felt like a fool.

You're right, it doesn't need to be an integer. I've been stressed, you'll have to forgive me:)

Thanks for trying to make sense of my ramblings though!
 
Well at least your "self" isn't a fool then!

Good luck!

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top