For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2007 > DecimalFormat.format() misbehaved on my machine









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DecimalFormat.format() misbehaved on my machine
ps

2007-08-27, 4:39 am

Hi,

I found this description in the API doc:

The number of significant digits in the mantissa is the sum of the
minimum integer and maximum fraction digits, and is unaffected by the
maximum integer digits. For example, 12345 formatted with "##0.##E0"
is "12.3E3".


But when I tried it out, I got different results:
System.out.println(new DecimalFormat("##0.##E0").format(12345)); //
prints 12.345E3

I then took one '#' away from both ends in turn, but still got
unexpected results:
System.out.println(new DecimalFormat("#0.##E0").format(12345)); //
prints 1.234E4
System.out.println(new DecimalFormat("##0.#E0").format(12345)); //
prints 12.34E3

My platform's Win Xp Pro x64 Sp2, and I'm using Java 1.6.

Has anyone else observed the same behavior on different platforms?

Regards,
PS

a24900@googlemail.com

2007-08-27, 4:39 am

On Aug 27, 7:13 am, ps <pausan....@gmail.com> wrote:
> But when I tried it out, I got different results:
> System.out.println(new DecimalFormat("##0.##E0").format(12345)); //
> prints 12.345E3


It's a four year old bug. And when reported it was already a few years
old:

http://bugs.sun.com/bugdatabase/vie...?bug_id=4871921

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com