| Author |
Formatting a value
|
Mezan Shareef
Ranch Hand
Joined: Apr 01, 2010
Posts: 40
|
|
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
Joined: Oct 27, 2005
Posts: 19216
|
|
java.util.Formatter, also available through String.format
java.text.DecimalFormat
Take your pick.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
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
Joined: Oct 13, 2005
Posts: 32694
|
|
|
If it's a JSP, it would sit better on that forum. Moving.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
Rule #1 of JSP: no Java code!
To format numbers, use the JSTL's <fmt:formatNumber> tag.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Mezan Shareef
Ranch Hand
Joined: Apr 01, 2010
Posts: 40
|
|
|
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
Joined: Jan 10, 2002
Posts: 56202
|
|
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
Joined: Apr 01, 2010
Posts: 40
|
|
|
Yes you are right, but i will do it afterwords. Now i am doing something else...
|
 |
 |
|
|
subject: Formatting a value
|
|
|