Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data type for currency computations

 
DANIELA PINES
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the best programming practice with regards to data type used for currency calculations in Java?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mr/Ms FRUIT,
Welcome to JavaRanch, the absolute best site on the www for Java information. We don't have many rules around here, but we do have one. Please change your display name to a first and last name to comply with the JavaRanch Naming Policy. You can change it here. Thank you for your cooperation.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the classic Test Infected paper that uses multiple currencies as an example to demonstrate JUnit and test-first practices. It might help you think about currency issues, and certainly has some good ideas about testing and coding.
There is a Currency class in Java, but I'm not really sure what it's good for yet.
 
Trond Hundstuen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.math.BigDecimal is the best suited for monetary calculations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic