bug in formatted output?

Discussion in 'Java' started by hugo, Aug 15, 2004.

  1. hugo

    hugo Guest

    I'm using jsdk 1.5 beta 2. I think there is a bug in the new formatted
    output and was wondering if anyone knows if it has been fixed in the
    newer beta 3 builds. Note that the output of 0.01 shows up as 0.10

    program:
    public class TestFormatting {
    public static void main(String [] args){
    System.out.format("%.2f\n",1.0);
    System.out.format("%.2f\n",0.1);
    System.out.format("%.2f\n",0.01);
    }
    }

    output:
    $ java -cp . TestFormatting
    1.00
    0.10
    0.10

    thanks
    hugo, Aug 15, 2004
    #1
    1. Advertising

  2. hugo

    hugo Guest

    (hugo) wrote in message news:<>...
    > I'm using jsdk 1.5 beta 2. I think there is a bug in the new formatted
    > output and was wondering if anyone knows if it has been fixed in the
    > newer beta 3 builds. Note that the output of 0.01 shows up as 0.10
    >
    > program:
    > public class TestFormatting {
    > public static void main(String [] args){
    > System.out.format("%.2f\n",1.0);
    > System.out.format("%.2f\n",0.1);
    > System.out.format("%.2f\n",0.01);
    > }
    > }
    >
    > output:
    > $ java -cp . TestFormatting
    > 1.00
    > 0.10
    > 0.10
    >
    > thanks



    Here's what I found in the java.sun.com bug database. It seems odd
    that this bug was first reported in February but is still reported as
    unfixed in 1.5 beta 3 snapshot 55 (18 june 04).


    Bug ID: 5002937
    Votes 0
    Synopsis (fmt) formatting for small floats losing exponent and
    rounding incorrectly
    Category java:classes_util
    Reported Against 1.5 , tiger-beta , tiger-beta2
    Release Fixed tiger-rc
    State Closed, fixed
    Related Bugs 5005649 , 5086406
    Submit Date 25-FEB-2004
    Description This code:
    class PrintfEks {
    public static void main(String[] args) {
    double number = 8.5;
    String format = "%9.2f\n";
    System.out.print("Format string: "+format);
    for (int i = 0; i < 8; i++) {
    System.out.print("(Number: "+number+") ");
    System.out.printf(format, number);
    number /= 10;
    }
    number = 0.085;
    System.out.print("(Number: "+number+") ");
    System.out.printf("%9.2f\n", number);
    }
    }

    produces the following

    Format string: %9.2f
    (Number: 8.5) 8.50
    (Number: 0.85) 0.85
    (Number: 0.08499999999999999) 0.84
    (Number: 0.008499999999999999) 0.84
    (Number: 8.499999999999998E-4) 0.84
    (Number: 8.499999999999998E-5) 0.84
    (Number: 8.499999999999998E-6) 0.84
    (Number: 8.499999999999998E-7) 0.84
    (Number: 0.085) 0.85


    completely wrong for number<0.85

    xxxxx@xxxxx 2004-02-25

    Work Around None

    Evaluation Oh my!

    This needs to be fixed as soon as possible.

    -- xxxxx@xxxxx 2004-02-25


    Comments
    Include a link with my name & email

    Submitted On 04-JUN-2004
    foxapple
    Still exists in JDK 1.5 Beta2


    Submitted On 18-JUN-2004
    cayhorstmann
    Still wrong in beta 3 snapshot 55.

    public class Test
    {
    public static void main(String[] args)
    {
    System.out.printf("%8.2f%n", 0.01); // prints 0.1
    }
    }


    Submitted On 19-JUL-2004
    Matei
    Also happens with plain %f;

    import static java.lang.Math.*;
    public class Test {
    public static void main(String[] args) {
    System.out.printf("%f%n", sin(PI)); // prints out 0.122464
    }
    }
    hugo, Aug 16, 2004
    #2
    1. Advertising

  3. hugo

    zoopy Guest

    On 16-8-2004 18:38, hugo wrote:

    > (hugo) wrote in message news:<>...
    >
    >>I'm using jsdk 1.5 beta 2. I think there is a bug in the new formatted
    >>output and was wondering if anyone knows if it has been fixed in the
    >>newer beta 3 builds. Note that the output of 0.01 shows up as 0.10
    >>
    >>program:
    >>public class TestFormatting {
    >> public static void main(String [] args){
    >> System.out.format("%.2f\n",1.0);
    >> System.out.format("%.2f\n",0.1);
    >> System.out.format("%.2f\n",0.01);
    >> }
    >>}
    >>
    >>output:
    >>$ java -cp . TestFormatting
    >>1.00
    >>0.10
    >>0.10
    >>
    >>thanks

    >
    >
    >
    > Here's what I found in the java.sun.com bug database. It seems odd
    > that this bug was first reported in February but is still reported as
    > unfixed in 1.5 beta 3 snapshot 55 (18 june 04).
    >
    >
    > Bug ID: 5002937
    > Votes 0
    > Synopsis (fmt) formatting for small floats losing exponent and
    > rounding incorrectly
    > Category java:classes_util
    > Reported Against 1.5 , tiger-beta , tiger-beta2
    > Release Fixed tiger-rc
    > State Closed, fixed
    > Related Bugs 5005649 , 5086406
    > Submit Date 25-FEB-2004

    [snipped bug description]

    According to <http://java.sun.com/j2se/1.5.0/snapshots/jdk15.b58.bugsfixed.list.html> it's been
    fixed in build 58 (of July 19). It received 0 votes, and Sun assigning it with severity 2 (out of 5,
    I think) and a priority of 3 (out of 5(?)) it probably was not considered a bug to be fixed early on.

    --
    Regards,
    Z.
    zoopy, Aug 16, 2004
    #3
  4. hugo

    hugo Guest

    (hugo) wrote in message news:<>...
    > (hugo) wrote in message news:<>...
    > > I'm using jsdk 1.5 beta 2. I think there is a bug in the new formatted
    > > output and was wondering if anyone knows if it has been fixed in the
    > > newer beta 3 builds. Note that the output of 0.01 shows up as 0.10
    > >
    > > program:
    > > public class TestFormatting {
    > > public static void main(String [] args){
    > > System.out.format("%.2f\n",1.0);
    > > System.out.format("%.2f\n",0.1);
    > > System.out.format("%.2f\n",0.01);
    > > }
    > > }
    > >
    > > output:
    > > $ java -cp . TestFormatting
    > > 1.00
    > > 0.10
    > > 0.10
    > >
    > > thanks

    >
    >
    > Here's what I found in the java.sun.com bug database. It seems odd
    > that this bug was first reported in February but is still reported as
    > unfixed in 1.5 beta 3 snapshot 55 (18 june 04).
    >
    >
    > Bug ID: 5002937
    > Votes 0
    > Synopsis (fmt) formatting for small floats losing exponent and
    > rounding incorrectly
    > Category java:classes_util
    > Reported Against 1.5 , tiger-beta , tiger-beta2
    > Release Fixed tiger-rc
    > State Closed, fixed
    > Related Bugs 5005649 , 5086406
    > Submit Date 25-FEB-2004
    > Description This code:
    > class PrintfEks {
    > public static void main(String[] args) {
    > double number = 8.5;
    > String format = "%9.2f\n";
    > System.out.print("Format string: "+format);
    > for (int i = 0; i < 8; i++) {
    > System.out.print("(Number: "+number+") ");
    > System.out.printf(format, number);
    > number /= 10;
    > }
    > number = 0.085;
    > System.out.print("(Number: "+number+") ");
    > System.out.printf("%9.2f\n", number);
    > }
    > }
    >
    > produces the following
    >
    > Format string: %9.2f
    > (Number: 8.5) 8.50
    > (Number: 0.85) 0.85
    > (Number: 0.08499999999999999) 0.84
    > (Number: 0.008499999999999999) 0.84
    > (Number: 8.499999999999998E-4) 0.84
    > (Number: 8.499999999999998E-5) 0.84
    > (Number: 8.499999999999998E-6) 0.84
    > (Number: 8.499999999999998E-7) 0.84
    > (Number: 0.085) 0.85
    >
    >
    > completely wrong for number<0.85
    >
    > xxxxx@xxxxx 2004-02-25
    >
    > Work Around None
    >
    > Evaluation Oh my!
    >
    > This needs to be fixed as soon as possible.
    >
    > -- xxxxx@xxxxx 2004-02-25
    >
    >
    > Comments
    > Include a link with my name & email
    >
    > Submitted On 04-JUN-2004
    > foxapple
    > Still exists in JDK 1.5 Beta2
    >
    >
    > Submitted On 18-JUN-2004
    > cayhorstmann
    > Still wrong in beta 3 snapshot 55.
    >
    > public class Test
    > {
    > public static void main(String[] args)
    > {
    > System.out.printf("%8.2f%n", 0.01); // prints 0.1
    > }
    > }
    >
    >
    > Submitted On 19-JUL-2004
    > Matei
    > Also happens with plain %f;
    >
    > import static java.lang.Math.*;
    > public class Test {
    > public static void main(String[] args) {
    > System.out.printf("%f%n", sin(PI)); // prints out 0.122464
    > }
    > }


    ok, I tried jsdk 1.5 beta 3, build 60 on both Solaris and Windows and
    this problem seems to be fixed.
    hugo, Aug 17, 2004
    #4
  5. hugo

    hugo Guest

    (hugo) wrote in message news:<>...
    > (hugo) wrote in message news:<>...
    > > I'm using jsdk 1.5 beta 2. I think there is a bug in the new formatted
    > > output and was wondering if anyone knows if it has been fixed in the
    > > newer beta 3 builds. Note that the output of 0.01 shows up as 0.10
    > >
    > > program:
    > > public class TestFormatting {
    > > public static void main(String [] args){
    > > System.out.format("%.2f\n",1.0);
    > > System.out.format("%.2f\n",0.1);
    > > System.out.format("%.2f\n",0.01);
    > > }
    > > }
    > >
    > > output:
    > > $ java -cp . TestFormatting
    > > 1.00
    > > 0.10
    > > 0.10
    > >
    > > thanks

    >
    >
    > Here's what I found in the java.sun.com bug database. It seems odd
    > that this bug was first reported in February but is still reported as
    > unfixed in 1.5 beta 3 snapshot 55 (18 june 04).
    >
    >
    > Bug ID: 5002937
    > Votes 0
    > Synopsis (fmt) formatting for small floats losing exponent and
    > rounding incorrectly
    > Category java:classes_util
    > Reported Against 1.5 , tiger-beta , tiger-beta2
    > Release Fixed tiger-rc
    > State Closed, fixed
    > Related Bugs 5005649 , 5086406
    > Submit Date 25-FEB-2004
    > Description This code:
    > class PrintfEks {
    > public static void main(String[] args) {
    > double number = 8.5;
    > String format = "%9.2f\n";
    > System.out.print("Format string: "+format);
    > for (int i = 0; i < 8; i++) {
    > System.out.print("(Number: "+number+") ");
    > System.out.printf(format, number);
    > number /= 10;
    > }
    > number = 0.085;
    > System.out.print("(Number: "+number+") ");
    > System.out.printf("%9.2f\n", number);
    > }
    > }
    >
    > produces the following
    >
    > Format string: %9.2f
    > (Number: 8.5) 8.50
    > (Number: 0.85) 0.85
    > (Number: 0.08499999999999999) 0.84
    > (Number: 0.008499999999999999) 0.84
    > (Number: 8.499999999999998E-4) 0.84
    > (Number: 8.499999999999998E-5) 0.84
    > (Number: 8.499999999999998E-6) 0.84
    > (Number: 8.499999999999998E-7) 0.84
    > (Number: 0.085) 0.85
    >
    >
    > completely wrong for number<0.85
    >
    > xxxxx@xxxxx 2004-02-25
    >
    > Work Around None
    >
    > Evaluation Oh my!
    >
    > This needs to be fixed as soon as possible.
    >
    > -- xxxxx@xxxxx 2004-02-25
    >
    >
    > Comments
    > Include a link with my name & email
    >
    > Submitted On 04-JUN-2004
    > foxapple
    > Still exists in JDK 1.5 Beta2
    >
    >
    > Submitted On 18-JUN-2004
    > cayhorstmann
    > Still wrong in beta 3 snapshot 55.
    >
    > public class Test
    > {
    > public static void main(String[] args)
    > {
    > System.out.printf("%8.2f%n", 0.01); // prints 0.1
    > }
    > }
    >
    >
    > Submitted On 19-JUL-2004
    > Matei
    > Also happens with plain %f;
    >
    > import static java.lang.Math.*;
    > public class Test {
    > public static void main(String[] args) {
    > System.out.printf("%f%n", sin(PI)); // prints out 0.122464
    > }
    > }


    ok, I tried jsdk 1.5 beta 3, build 60 on both Solaris and Windows and
    this problem seems to be fixed.
    hugo, Aug 17, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe C
    Replies:
    4
    Views:
    384
    Ron Natalie
    Dec 25, 2004
  2. Mastupristi

    formatted output with cout

    Mastupristi, Feb 24, 2005, in forum: C++
    Replies:
    5
    Views:
    910
    Samuel Krempp
    Mar 25, 2005
  3. silly
    Replies:
    2
    Views:
    380
    silly
    Nov 11, 2003
  4. Joe Flynt
    Replies:
    5
    Views:
    708
    Dennis Lee Bieber
    Nov 9, 2003
  5. Mark

    Formatted numerical output

    Mark, Nov 28, 2004, in forum: Python
    Replies:
    2
    Views:
    277
Loading...

Share This Page