Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > bug in formatted output?

Reply
Thread Tools

bug in formatted output?

 
 
hugo
Guest
Posts: n/a
 
      08-14-2004
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
 
Reply With Quote
 
 
 
 
hugo
Guest
Posts: n/a
 
      08-16-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
> 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
}
}
 
Reply With Quote
 
 
 
 
zoopy
Guest
Posts: n/a
 
      08-16-2004
On 16-8-2004 18:38, hugo wrote:

> (E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
>
>>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.
 
Reply With Quote
 
hugo
Guest
Posts: n/a
 
      08-17-2004
(E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
> (E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
> > 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.
 
Reply With Quote
 
hugo
Guest
Posts: n/a
 
      08-17-2004
(E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
> (E-Mail Removed) (hugo) wrote in message news:<(E-Mail Removed). com>...
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
formatted data leaf VHDL 8 02-09-2006 03:25 AM
How do I get nicely-formatted times? Leif K-Brooks Firefox 1 11-20-2003 10:22 PM
Server-side Printing With Formatted Text Stuart Woodard ASP .Net 0 08-03-2003 05:53 PM
Help needed formatted submit results - Changing data Robert V Perl 1 07-19-2003 12:49 AM



Advertisments