From: Eric Sosman on 29 Jul 2010 07:26 On 7/29/2010 1:52 AM, Roedy Green wrote: > On Thu, 29 Jul 2010 00:22:32 -0400, Eric Sosman > <esosman(a)ieee-dot-org.invalid> wrote, quoted or indirectly quoted > someone who said : > >> >> NumberFormat fmt = new DecimalFormat("#.##"); >> >> This will format 1.20 as "1.2" and 3.45 as "3.45". > > Any is there a way to trim .00 to get rid of the dot too, or is that > the default behaviour? fmt.setDecimalSeparatorAlwaysShown(false); -- Eric Sosman esosman(a)ieee-dot-org.invalid
From: John B. Matthews on 29 Jul 2010 10:10 In article <sk5256ll6m6kerkvj82e5pdisqgeeobj23(a)4ax.com>, Roedy Green <see_website(a)mindprod.com.invalid> wrote: > On Thu, 29 Jul 2010 00:08:23 -0400, "John B. Matthews" > <nospam(a)nospam.invalid> wrote, quoted or indirectly quoted someone who > said : > > >I'm pretty sure you'd have to convert the String to a Number, long or > >double before you could format() it. > > I have it as a double. Ah, you only mentioned string. Eric's answers are what you want. [...] -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Roedy Green on 29 Jul 2010 18:47 On Wed, 28 Jul 2010 22:52:19 -0700, Roedy Green <see_website(a)mindprod.com.invalid> wrote, quoted or indirectly quoted someone who said : > >Any is there a way to trim .00 to get rid of the dot too, or is that >the default behaviour? I found that .### works exactly as needed, dropping the dot for .000. Thanks. -- Roedy Green Canadian Mind Products http://mindprod.com You encapsulate not just to save typing, but more importantly, to make it easy and safe to change the code later, since you then need change the logic in only one place. Without it, you might fail to change the logic in all the places it occurs.
First
|
Prev
|
Pages: 1 2 Prev: Apache Tomcat https link goes down but http works Next: Testing As Proof |