Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle Currency in Java 8?

What is the preferred way to handle currencies in Java 8?

The things that could be of interest would be

* Currency Full Name (e.g. United States Dollar)  
* Currency Abbreviation (e.g. USD)  
* Currency Symbol (e.g. $)  

Any other thing that I might be missing here?

What are the best options?

like image 270
daydreamer Avatar asked Jun 11 '26 22:06

daydreamer


1 Answers

Java 8 still uses java.util.Currency and ISO 4217 codes. From the Javadoc,

Represents a currency. Currencies are identified by their ISO 4217 currency codes. Visit the ISO web site for more information, including a table of currency codes.

The class is designed so that there's never more than one Currency instance for any given currency. Therefore, there's no public constructor. You obtain a Currency instance using the getInstance methods.

Users can supersede the Java runtime currency data by means of the system property java.util.currency.data.

like image 166
Elliott Frisch Avatar answered Jun 14 '26 12:06

Elliott Frisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!