Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. pad zero in front of long value?

pad zero in front of long value?

Scheduled Pinned Locked Moved C / C++ / MFC
javaquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    valerie99
    wrote on last edited by
    #1

    morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005

    D B 2 Replies Last reply
    0
    • V valerie99

      morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      I'm not sure why you asked a Java question in a C++ forum.

      valerie99 wrote:

      when the string got convert to long, it lost the leading zero, could it just be padded back...

      No. Numbers with leading zeros are for display purposes only. If you had:

      char *szNumber = "01234";

      and you assigned that to a long via:

      long lNumber = atol(szNumber);

      why would you want lNumber to be equal to 01234 instead of 1234?


      "Take only what you need and leave the land as you found it." - Native American Proverb

      V 2 Replies Last reply
      0
      • V valerie99

        morning, when the string got convert to long, it lost the leading zero, could it just be padded back or it should be converted back to string to add the zero? here is the code, sorry, it's java String t = party.getNumber().getNNxx(); t = rightTrim( t.substring( offset, t.length() ) ); while( t.length() > 0 ) { long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); t = t.substring( 0, t.length()-1 ); String szCountry = Long.toString( party.getCountry() ); long token = cintCity.find( (long) party.getCountry(), city ); if ( token != cintCity.end() ) { party.setCityCode( city ); thanks. -- modified at 12:08 Friday 21st October, 2005

        B Offline
        B Offline
        bugDanny
        wrote on last edited by
        #3

        David's exactly right. No number with actual meaning has leading 0's, unless it's the 0 before the decimal point. The program shouldn't keep track of that, so you'll have to pad that back, if you really want it. Danny The stupidity of others amazes me!

        1 Reply Last reply
        0
        • D David Crow

          I'm not sure why you asked a Java question in a C++ forum.

          valerie99 wrote:

          when the string got convert to long, it lost the leading zero, could it just be padded back...

          No. Numbers with leading zeros are for display purposes only. If you had:

          char *szNumber = "01234";

          and you assigned that to a long via:

          long lNumber = atol(szNumber);

          why would you want lNumber to be equal to 01234 instead of 1234?


          "Take only what you need and leave the land as you found it." - Native American Proverb

          V Offline
          V Offline
          valerie99
          wrote on last edited by
          #4

          thanks, David. I need that 0 because it's the phone number, 0123 is different as 123.......thanks for your help.

          1 Reply Last reply
          0
          • D David Crow

            I'm not sure why you asked a Java question in a C++ forum.

            valerie99 wrote:

            when the string got convert to long, it lost the leading zero, could it just be padded back...

            No. Numbers with leading zeros are for display purposes only. If you had:

            char *szNumber = "01234";

            and you assigned that to a long via:

            long lNumber = atol(szNumber);

            why would you want lNumber to be equal to 01234 instead of 1234?


            "Take only what you need and leave the land as you found it." - Native American Proverb

            V Offline
            V Offline
            valerie99
            wrote on last edited by
            #5

            thanks, David. I need that 0 because it's the phone number, 0123 is different as 123 in some country's city code.......thanks for your help.

            D 1 Reply Last reply
            0
            • V valerie99

              thanks, David. I need that 0 because it's the phone number, 0123 is different as 123 in some country's city code.......thanks for your help.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Ok, but how are you using that number? Are you sending it to a modem for dialing purposes?


              "Take only what you need and leave the land as you found it." - Native American Proverb

              V 1 Reply Last reply
              0
              • D David Crow

                Ok, but how are you using that number? Are you sending it to a modem for dialing purposes?


                "Take only what you need and leave the land as you found it." - Native American Proverb

                V Offline
                V Offline
                valerie99
                wrote on last edited by
                #7

                I think this shouldn't been done as long since it's for display not conculation, leading zero is meaningful at this point. I could left pad zero in front of string, long city = ( party.getCityCode() == 0 ? Long.parseLong( t.toString() ) : party.getCityCode() ); String szcity = utils.leftPadZeros( String.valueOf( city ), t.length()); long token = cintCity.find2( szCountry, szcity ); but the whole app is using long for citycode, it might cause problem later on party.setCityCode( city ); so I was wondering if I could pad zero in front of long....seems like impossible... thanks, have a good weekend

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups