keep my 6 digit int 6 digits!!

Mooz

Moozically Con~foozed
Joined
Jul 16, 2002
Messages
126
#3
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
Mar 18, 2002
Messages
7,805
#4
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
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,979
Messages
673,322
Members
89,018
Latest member
Pdawginhere