2 Replies Latest reply: Jun 10, 2014 9:22 AM by rp0428 RSS

    leading zeros been trim

    Tshifhiwa

      hi i got situation where i have postal code as 0009 in database and the use is entering 0009 but somehow in my java code it only reading 9 from the xml file

       

      this is how i define getter and setter

       

      when i deburg the code i get this

      passed postalcode 9

       

      if a user enterd 0009 i what it to remain 0009

       

      Java Code:

       public String Postalcode="";   
      public void setPostalcode(String Postalcode) { this.Postalcode = Postalcode; }
        public String getPostalcode() { return Postalcode; }
        • 1. Re: leading zeros been trim
          jwenting

          You're no doubt treating the code as an integer somewhere along the way, causing of course the leading zeros to be stripped as 0009 as a number is 9. Then when you're converting back somewhere else, you're doing that without prepending leading zeros to guarantee whatever minimum length you're needing.

           

          And none of that is in the code you showed btw.

          • 2. Re: leading zeros been trim
            rp0428
            hi i got situation where i have postal code as 0009 in database and the use is entering 0009 but somehow in my java code it only reading 9 from the xml file

             

            if a user enterd 0009 i what it to remain 0009

             

            What database and version? What is the datatype of the column where postal code is stored.

             

            If a user entered 0009 WHERE? How does the user enter the data? What object is the data entered into?