• Post Reply Bookmark Topic Watch Topic
  • New Topic

Number format  RSS feed

 
selvi family
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • 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
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!