• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Format an int to a price

 
Ryan Callen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd check to see if NumberFormat (or its extenders) was of any help.
 
Ryan Callen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read my response again carefully.
 
Ryan Callen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DecimalFormat seems to work, but i can't figure out the correct pattern to use.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getCurrencyInstance() isn't cutting the mustard?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic