bug in formatted output?

H

hugo

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
 
H

hugo

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
}
}
 
Z

zoopy

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.
 
H

hugo

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.
 
H

hugo

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top