|
From: Rakesh on 7 Jul 2008 17:26 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 7 Jul 2008 18:11 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 8 Jul 2008 06:29 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)
|
Pages: 1 Prev: I don't understand the error Next: Maven or Wicket pre-built? |