keep my 6 digit int 6 digits!!

Discussion in 'Web Design & Coding' started by dubstar, May 12, 2007.

  1. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    C++

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

    how do i stop that?
     
  2. LordOfLA

    LordOfLA Godlike!

    Messages:
    7,027
    Location:
    Maidenhead, Berkshire, UK
    you don't. you use formatting statements in your printf/puts statements :)
     
  3. Mooz

    Mooz Moozically Con~foozed

    Messages:
    126
    Location:
    UK
    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. :)
     
  4. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    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
     
  5. dubstar

    dubstar format c:

    Messages:
    1,357
    Location:
    Southern California
    thanks guys. sorry it took so long. your direction is much appreciated.