Java Format number as currency

Previous
Next

In this post, we are going to see how to format currency in java.

We can format number into Currency by using NumberFormat class.We need to call NumberFormat.getInstance()  to get NumberFormat object by passing specified locale.
For example:
Let’s say you want a Format object for UK Locale or US Locale. You can simply use below code:

Here Locale represents currency for number conversion.
Then we will call NumberFormat’s format method to simply format number into currency.

Java program for formatting a number into currency

OUTPUT:

£9,876.89 British Pound
$9,876.89 US Dollar
9 876,89 € Euro

That’s all about formatting number in currency in java.

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog