Avatar of stevelopez
stevelopez
 asked on

How to customize java getCurrencyInstance for negative values

I need to have negative USD values display with a negative sign instead of the parenthesis (e.g. '$-10.00' instead of '$(10.00)'.

I didn't see any obvious ways to change the formatter.  Assistance much appreciated.
I am currently using: java.text.NumberFormat nf = java.text.NumberFormat.getCurrencyInstance();
 
(default localte is USD)

Open in new window

Java EEJava

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon
Mick Barry

Use setNegativePrexix() and setNegativeSuffix() in the DecimalFormat class

stevelopez

ASKER
Can you provide an example where the resulting formatter is still a Currency Instance? (e.g. provides all the other formatting aspects that come with the Currency formatter and not just the plain DecimalFormat)

I ask this because I do not see those methods being available when using getCurrencyInstance:

java.text.NumberFormat nf = java.text.NumberFormat.getCurrencyInstance(Locale.US);
There is no such method: nf.setNegativePrefix("-").
ASKER CERTIFIED SOLUTION
Mick Barry

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck