keep my 6 digit int 6 digits!!

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
C++

taking in an Emp ID for a project, it turns "000001" into "1"

how do i stop that?
 

LordOfLA

Godlike!
Joined
2 Feb 2004
Messages
7,026
you don't. you use formatting statements in your printf/puts statements :)
 

Mooz

Moozically Con~foozed
Joined
16 Jul 2002
Messages
126
I agree this is a commonly raised issue with newb programmers.

I guess the easiest explanation i have given in the past is that from an internal system perspective you dont need the leading 0's as the take up space when stored in a database. To this extent the leading zeros are only used for presentation.

psuedo VB code.

dim iNum as integer
dim sString as string
dim sOutput

sString = "000000"
iNum = 1

sOutput = RIGHT (sStr & cStr(iNum),6)

'from the above the sOutput would be left as "000001"

if you then need to read the int value simply cInt(sOUtput) would return 1

sorry for the vb but i am not a c# programmer.

regards,

D

ps. if this post has helped please press the star and leave some rep. :)
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
As LordOfLA said its pretty much all down to the formatting when you output it.

If you specifically need something like this then you'd probably want to create a structure with an array of numbers in it, but you would then need to write functions to ensure no array index had a number greater than 9.

something along the lines of
Code:
printf("%06d", emp_id);
might do it though I have admittedly not tested it
 

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
thanks guys. sorry it took so long. your direction is much appreciated.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,011
Messages
673,478
Members
5,608
Latest member
endryshall