File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Formatting a value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Formatting a value" Watch "Formatting a value" New topic
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
    
    2

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
    
    4
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
    
  13

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
    
  13

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...
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Formatting a value
 
Similar Threads
Question on jQuery ajax functionality & troubleshooting called bean in JSF page
HTML does not print properly - table width exceeding 100%?
INCLUDES.DBconnection error
Make rows not appear when certain row value appears
Number Format Exception