• Post Reply Bookmark Topic Watch Topic
  • New Topic

Formatting a value  RSS feed

 
Mezan Shareef
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code, There is object of type hashmap (h). I am working on JSP page. there are two values h.get ("drUnitCost") and h.get ("shippingFee") as 5.2345, and 0.3456 respectively. What i want is $5.23 and $0.34 for h.get ("drUnitCost") and h.get ("shippingFee") respectively.

unit cost and shipping fee these are the colums in my page and other few coumns like order details, order id, product code etc.



Order Detail # Order Detail Item ID Supplier Product Code (SKU) Product Name Status Unit

order
detail#
unitcost shipping fee Tracking Number status date
441238 8.3200 0.3900 1Z9999W99999999999 01/15/2010
441238 8.3200 0.3900 abc123 01/15/2010
441238 8.3200 0.3900 abc123 01/15/2010

Please help.Thank you.
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.Formatter, also available through String.format
java.text.DecimalFormat

Take your pick.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, since it's a JSP we're discussing here, the relevant things to learn would be the JSTL or EL constructs for formatting numbers. Using Java constructs just reinforces the bad habit of including Java code in a JSP.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a JSP, it would sit better on that forum. Moving.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rule #1 of JSP: no Java code!

To format numbers, use the JSTL's <fmt:formatNumber> tag.
 
Mezan Shareef
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys. I did it. I used java. To configure JSTL again it was like pain, so i did with java, very soon i will do with JSTL later.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66153
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mezan Shareef wrote:Thank you guys. I did it. I used java. To configure JSTL again it was like pain, so i did with java, very soon i will do with JSTL later.

Do it now. The longer you continue with bad habits, the harder they are to break.
 
Mezan Shareef
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right, but i will do it afterwords. Now i am doing something else...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!