This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Format an int to a price Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Format an int to a price" Watch "Format an int to a price" New topic
Author

Format an int to a price

Ryan Callen
Greenhorn

Joined: Nov 29, 2012
Posts: 22
I'm writing a method that accepts a price in cents as an int and then prints it out as a price in in dollars and cents. For example, '99' would print as '$0.99' and '125' would print as '$1.25' and '1000345' would print as '$10003.45'. Any ideas?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

I'd check to see if NumberFormat (or its extenders) was of any help.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ryan Callen
Greenhorn

Joined: Nov 29, 2012
Posts: 22
NUmberFormat doesn't seem to have the solution I'm looking for. I was thinking more along the lines of formatting the int like a decimal?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Read my response again carefully.
Ryan Callen
Greenhorn

Joined: Nov 29, 2012
Posts: 22
DecimalFormat seems to work, but i can't figure out the correct pattern to use.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

getCurrencyInstance() isn't cutting the mustard?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format an int to a price
 
Similar Threads
Illegal start?
java bean
beginner precision question
What is wrong with my java code?
If Statement Help