aspose file tools*
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 Spring in Action this week in the Spring 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: 61413
    
  67

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: 61413
    
  67

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: 61413
    
  67

getCurrencyInstance() isn't cutting the mustard?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format an int to a price