• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Number format

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am getting the values of price from Databse and Stored in resultset.
From resultset i put the values in ArrayList.
Now i want to display the value in ###.00 format.

For example if the price is 40 , it has to be displayed as 40.00 and if the price is 50.5, it has to be dispalyed as 50.50.

I am using a NumberFormat class.but not getting the proper results.

The following is my code:

String total=(String)sum1.get(i);
NumberFormat nf = NumberFormat.getNumberInstance(Locale.ENGLISH);
out.println("$" +nf.parse(nf.format(total)))

sum1 is a arraylist.

What is wrong in this code?

Please help me to do this

thanks
selvi
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by selvi family:
out.println("$" +nf.parse(nf.format(total)));

In this line, you're formatting the Number into a String and then immediately parsing that String back to a Number. Change it to
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think format() takes a String argument. You will get an IllegalArgumentException.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

[ January 11, 2005: Message edited by: Mike Gershman ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I missed that total was a String and not already a double. Thanks Mike!
 
selvi family
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mike..

I implemented the code sent by u...It is working fine....

My problem is solved..

Thanks a lot.
 
reply
    Bookmark Topic Watch Topic
  • New Topic