From: Rakesh on
For a particular application - I need to format decimals with strictly
6 digits , after the decimal separator (even if they are not
significant ).

More specifically I would like the following test case to succeed.

public void testZeroFormatting() {
DecimalFormat myformat = new DecimalFormat("#############.######");
assertEquals("Zero ", "0.000000", myformat.format(0.0f));
}


For now , the function returns 0, instead of 0.000000 (as I want it
to). Any idea what I am missing here.

From: Martin Gregorie on
On Mon, 07 Jul 2008 14:26:32 -0700, Rakesh wrote:

> For now , the function returns 0, instead of 0.000000 (as I want it to).
> Any idea what I am missing here.

DecimalFormat myformat = new DecimalFormat("############0.000000");

....as it says quite clearly in the DecimalFormat documentation.

If for some reason you don't have the JDK documentation installed,
you need to rectify that omission ASAP.


--
martin@ | Martin Gregorie
gregorie. |
org | Zappa fan & glider pilot


From: GArlington on
On Jul 7, 10:26 pm, Rakesh <rakesh.use...(a)gmail.com> wrote:
> For a particular application - I need to format decimals with strictly
> 6 digits , after the decimal separator (even if they are not
> significant ).
>
> More specifically I would like the following test case to succeed.
>
> public void testZeroFormatting() {
> DecimalFormat myformat = new DecimalFormat("#############.######");
> assertEquals("Zero ", "0.000000", myformat.format(0.0f));
> }
>
> For now , the function returns 0, instead of 0.000000 (as I want it
> to). Any idea what I am missing here.

You need to RTFM.
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html
(Special Pattern Characters)