How do I get NumberFormat.getCurrencyInstance()
to print negative USD currency values with a minus sign?
Advertisement
Answer
Since I faced this problem again, I did some research and found a more resilient solution provided by the ICU:
NumberFormatter .withLocale(...) .unit(Currency.getInstance("USD")) .sign(SignDisplay.AUTO) // "123", "0", and "-123" .format(123) .toString();
Check the API documentation of NumberFormatter for more details.