Am having an issue with formatting currencies in Java. I am trying to format a number to be printed as currency, with all the decimal points aligned:
£ 1.23
£ 12.34
£123.45
Calling NumberFormat.getCurrencyInstance().format(n)
returns a formatted string, but all the numbers are left-aligned, producing output like this:
£1.23
£12.34
£123.45
Ugly. I have read this post which presents a solution using a DecimalFormat
, and as a stopgap I'm formatting my number using a DecimalFormat and prepending the currency symbol later, but I was wondering if anyone was aware of a neater way of accomplishing the same thing?
Hope that's all clear, thanks in advance for your help!