How to design Money Class in Java ?

By | August 18, 2019

In this post we will talk and learn How to design Money Class in Java  ? 

Money is basically composed of two fundamental entities Amount and Currency.
The BigDecimal is ideal data type provided in Java language for representing monetary values and Java also provides
Currency Class implementation.

Money class

The code shown above is not thread safe, ideally NumberFormat should be created local to a thread using ThreadLocal class instead making it a static field of class.

Client program 

Sample output of above program:

Amount = $900.00

That’s all about How to design Money Class in Java?

You May Also Like:

Which data type would you choose for storing currency values like Trading Price in Java?
How would you print a given currency value for Indian Locale (INR Currency)?
Which classes in java are immutable ?
How would you round a double value to certain decimal Precision and Scale ?
What is BlockingQueue? How can we implement Producer and Consumer problem using Blocking Queue?
How to get number of available processors in Java ?

If you have any feedback or suggestion please feel free to drop in blow comment box. 

Leave a Reply

Your email address will not be published. Required fields are marked *