10 Replies Latest reply: Jul 2, 2008 10:40 AM by 843785 RSS

    Convert a big decimal to int

    807601
      Hi I want to convert a Big decimal value to int.

      pl help
        • 1. Re: Convert a big decimal to int
          795426
          Good for you. What have you tried? What do you need help with figuring out?
          • 2. Re: Convert a big decimal to int
            807601
            If only there was some sort of comprehensive documentation of all the methods available on all classes in the JDK, eh! Then you'd be able to just look up, say, the intValue method
            • 3. Re: Convert a big decimal to int
              807601
              Congratulations.

              Learn to use the API: [http://java.sun.com/javase/6/docs/api/]
              Or just google "java 6 api"

              Or for a specific class, google "java 6 [classname]"
              So here, google "java 6 bigdecimal" and the first result is this: [http://java.sun.com/javase/6/docs/api/java/math/BigDecimal.html]

              Scroll down to the list of methods and you'll find your answer.
              • 4. Re: Convert a big decimal to int
                JosAH
                georgemc wrote:
                If only there was some sort of comprehensive documentation of all the methods available on all classes in the JDK, eh! Then you'd be able to just look up, say, the intValue method
                But that implies a 'reading' capability; reading is an almost lost art form nowadays in this 'information age', people want to copy and paste exactly what they were asking for; probably more but no less and most certainly no 'reading' involved, it makes your eyeballs hurt. I always keep wondering about why people go through all that trouble of writing extensive help files and help systems; they are never read ... better include a kool game with your application and make people win mugs and T-shirts and such ...

                kind regards,

                Jos ;-)
                • 5. Re: Convert a big decimal to int
                  634908
                  From documentation:
                  "The BigDecimal class gives its user complete control over rounding behavior"
                  So you have select how you need round and use appropriative method.
                  • 6. Re: Convert a big decimal to int
                    843785
                    i havea method getchild
                    projectdesc is an Object class
                    g_list is JLISt with fields in it
                    getID will return BigDecimal value
                    when I do this below code it says cannot return bigdecimal value (this fine b'coz the method return a int value). Now how to convert Bigdecimal into int. I looked at the document .. but still having troubles.... please help
                    public int getchild(Object parent , int index)
                    {
                    projectdesc a = new projectdesc();
                    
                    if(parent instance of string)
                    {
                    for(int i = 0; i<g_list.size{}; i++)
                    
                    return ( a.getId(new BigDecimal(i);
                    
                    }
                    • 7. Re: Convert a big decimal to int
                      795426
                      Ignoring the fact that that code will never compile, why does your .get() method take any arguments? For that matter, why do you have a return statement as the only statement in a loop?
                      • 8. Re: Convert a big decimal to int
                        843785
                        getId method will take Bigdecimal values.
                        i hev only return statement to return the value of the child do I could see the fields in the view . as a Tree structure
                        • 9. Re: Convert a big decimal to int
                          795426
                          machinechip wrote:
                          getId method will take Bigdecimal values.
                          Why? There is no reason for an accessor method to require any arguments.
                          i hev only return statement to return the value of the child do I could see the fields in the view . as a Tree structure
                          Bzzzt. As soon as you hit that return statement, you leave the method. Your loop will never progress past its first iteration.
                          • 10. Re: Convert a big decimal to int
                            843785
                            public BigDecimal getId() {
                            return groupId; // ID
                            }