Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 21 of 21

Thread: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    // my code here
    String pdecimal = Double.toString(guess);
    contents of 'guess' ---->>0.00891396012251904
    The result string field 'pdecimal' displays -->> 0.00) <<--
    That is to say "zero point zero zero parenthesis".
    Only with very few numbers such as above does the bug show up.
    Using ECLIPSE Version: 3.4.2
    Build id: M20090211-1700
    Other 'toString's in program work ok.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    It works perfectly fine for me. Post a SSCCE.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    I think its a case of the IDE doing something on its own vs using Oracle's programs.

  4. #4
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Norm View Post
    I think its a case of the IDE doing something on its own vs using Oracle's programs.
    i agree; in other java programs the number converts ok. but when i filed a bug on ECLIPSE forum they said it was a java problem.
    ...thanks for your reply...

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Junky View Post
    It works perfectly fine for me. Post a SSCCE.
    what's SSCCE? i already posted problem as a bug on ECLIPSE forum.
    i agree; in other java programs the number converts ok. but when i filed a bug on ECLIPSE forum they said it was a java problem.
    ...thanks for your reply...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    on ECLIPSE forum they said it was a java problem.
    Did they say which version of java?
    This works for me on 3 versions of java:
          double dbl = 0.00891396012251904;
          System.out.println("dbl=" + Double.toString(dbl));  // dbl=0.00891396012251904

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by jforumohn View Post
    what's SSCCE?
    An SSCCE is a short, self-contained, compilable example.

    If you think you found a bug, chances are you haven't. Post the exact, full code (but shortened to take out anything extra) that you're using when you get the weird behavior.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    The result string field 'pdecimal' displays -->> 0.00) <<--
    You have not shown the code that displays the value in your posting.
    Can you post the code that displays that value?

  9. #9
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    //for test plug 19549.3120187621 into 'principal'
    //for test plug 60 into 'term'
    //for test plug 333.33 into 'payment'
    //with above values the double field 'guess' will contain 0.00891396012251904 after the computations
    //****interest click button***********
        	 public void continueclick (View view)
        	 {
     
    if (text.getText().length() == 0)
    	    	    	{
    	    				Toast.makeText(this, "Please enter a valid principal number",
    	    						Toast.LENGTH_LONG).show();
    	    				return;
     
    	    			}
    if (text3.getText().length() == 0)
    						 {
    							Toast.makeText(this, "Please enter a valid term number",
    							Toast.LENGTH_LONG).show();
    						return;
    			    			}
    if (text4.getText().length() == 0)
    						 {
    							Toast.makeText(this, "Please enter a valid payment number",
    							Toast.LENGTH_LONG).show();
    						return;
    			    			}
     
    //****************
    double term = Float.parseFloat(text3.getText().toString());
    double payment = Float.parseFloat(text4.getText().toString());
    double principal = Float.parseFloat(text.getText().toString());
       double P = principal;
       double lowguess = .0001;
    double n = term;
        double avgterm = (n / 12);
        double ncount = n;
        double compound = 0;
        char done = 'n';
        //---------------
        //n = number of months
        double temp = avgterm * lowguess;
        double temp1 = principal * temp; //1 month interest
        //principal * interest * 1 month = payment
        compound = 0;
        ncount = n;
        double guess = .000001;
        double toohi = .999;
        double toolo = .001;
        double pmt1 = 0;
        guess = .05;
        int savedcounter = 0;
        guess = guess / 12;
        while (done == 'n')
        {
            ncount = n;
            compound = 0;
            principal = P;
     
     
            double i = guess;
     
                temp = 1 + i;
                double temp2 = Math.pow(temp, n);
                temp1 = i * temp2;
                double temp3 = temp2 - 1;
                double temp4 = temp1 / temp3;
                double temp5 = P * temp4;
     
                pmt1 = temp5;
            temp4 = Math.abs(payment - pmt1);
     
            if (pmt1 == payment)
            {
                done = 'y';
            }
            if (temp4 < .1)
            {
                done = 'y';
            }
            if (done == 'n')
            {
                if (pmt1 > payment)
                {
                    toohi = guess;
                    temp = toohi - toolo;
                    temp1 = temp / 2;
                    guess = toohi - temp1;
                    double perpayofpmt = payment / pmt1;
                }
                if (pmt1 < payment)
                {
                    toolo = guess;
                    temp = toohi - toolo;
                    temp1 = temp / 2;
                    guess = toolo + temp1;
                    double perpmtofpay = pmt1 / payment;
     
                }
                int tempout = 25;
                if (savedcounter > tempout)
                {
     
                    if (pmt1 < payment)
                    {
                        guess = guess * tempout;
                      //  temp5 = guess * perpmtofpay;
                      //  guess = guess + temp5;
                    }
                    if (pmt1 > payment)
                    {
                        guess = guess / tempout;
                       // temp5 = guess * perpayofpmt;
                       // guess = guess - temp5;
                    }
                    tempout = tempout + 25;
     
                }
                savedcounter++;
     
     
                if (savedcounter > 5000)
                {
     
                    done = 'y';
                }
            } //end if done bracket
        } //done loop
     
     
        guess = guess * 12;
        String pdecimal = Double.toString(guess);
     
     
        pdecimal = pdecimal.replace("*","99999");
        pdecimal = pdecimal.replace(")","89139");
     
    text2.setText(pdecimal);
     
    text5.setText(String.valueOf(savedcounter));
    text6.setText(String.valueOf(pmt1));
     
    if (savedcounter == 5001)
    	    	    	{
    	Toast.makeText
    	(this, "PAYMENT IS OFF TOO MUCH...TRY TO GUESS BETTER PAYMENT...SEE CLOSEST PAYMENT WINDOW",
    	Toast.LENGTH_LONG).show();
    	    	    	}
     
        	 }

  10. #10
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Sorry, but that's not an SSCCE. I'm willing to bet that your "bug" is really a result of whatever that code is doing. Your SSCCE should only be a few lines long, and it should be a complete class with a main method so we can copy and paste it.

    Sorry, but you have no idea how often somebody cries "bug!" when really it's just a silly mistake or a misunderstanding of how things work.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    What do we need to do with the code you posted to get the result that this thread is talking about?

    The posted code isn't in a class with a main() method so what do we do with it???

    You need to create code that generates the bad results for you.
    Then post that same exact code so we can see if we get the problem.

  12. #12
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    pdecimal = pdecimal.replace("*","99999");
        pdecimal = pdecimal.replace(")","89139");

    the above 2 instructions only serve to replace the spurious ")" and "*".

  13. #13
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Norm View Post
    Did they say which version of java?
    This works for me on 3 versions of java:
          double dbl = 0.00891396012251904;
          System.out.println("dbl=" + Double.toString(dbl));  // dbl=0.00891396012251904
    ***my reply***
    i didn't make it clear...ECLIPSE people just assumed it was a java problem but not a known java problem.
    ...thanks for your replies...

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    If your not going to post code (a SSCCE) then you might as well close this thread.
    Nothing can be done without code that shows the problem.

  15. #15
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    to reproduce the error you'd have to...
    1. be in 'ECLIPSE Version: 3.4.2 Build id: M20090211-1700' within an ANDROID cellphone project.
    2. have a text field like this...
    <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:textSize = "15sp"
    android:inputType="numberDecimal|numberSigned"
    android:enabled="true" android:id="@+id/editText2"
    android:text=" ">
    </EditText>

    3. have a double contaning 0.00891396012251904.
    4. execute...
    String pdecimal = Double.toString(guess); where 'guess' is the double in item 3 above.
    5. execute...
    text2.setText(pdecimal); where 'text2' is item 2 above.
    doing the above will result in 'text2' window showing...
    0.00)
    ...in the CELLPHONE EMULATOR WINDOW.

    i have a java applet with same code that displays 0.00891396012251904 properly in the applet window.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    That environment has a lot in it beside Java. How about a problem with Android?

  17. #17
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Norm View Post
    That environment has a lot in it beside Java. How about a problem with Android?
    duh...try to tell the ECLIPSE and ANDROID people that.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    What is output if you write the String to the log?
    Or any other debug output screen?

  19. #19
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Norm View Post
    What is output if you write the String to the log?
    Or any other debug output screen?
    the problem was with ECLIPSE GANAMEDE. ECLIPSE GALELIO (GALALEO?) works ok. it is a blasted BUG in ECLIPSE GANAMEDE!
    ...thanks for your interst...i appreciate it.

  20. #20
    Junior Member
    Join Date
    Jun 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Quote Originally Posted by Junky View Post
    It works perfectly fine for me. Post a SSCCE.
    the problem was with ECLIPSE GANAMEDE. ECLIPSE GALELIO (GALALEO?) works ok. it is a blasted BUG in ECLIPSE GANAMEDE!
    ...thanks for your interst...i appreciate it.

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Double.toString bug. Spurious right parenthesis and an asterisk replace digits.

    Glad you were able to isolate it.
    Now we can all have complete faith in Oracle's java again.

Similar Threads

  1. help with loop to print an equliateral asterisk triangle
    By everyone0 in forum Loops & Control Statements
    Replies: 13
    Last Post: October 11th, 2012, 12:37 PM
  2. Please help! Nested while loops and asterisk triangles!
    By rockout341 in forum Loops & Control Statements
    Replies: 12
    Last Post: September 15th, 2011, 11:50 AM
  3. Remove last digits of an IP address.
    By Jonathan_C in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 15th, 2010, 12:55 PM
  4. asterisk forming diamond
    By cutee_eyeh in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 13th, 2010, 08:53 PM

Tags for this Thread