Setting decimal sign ("+" AND "-") in DecimalFormat ?

M

Mark Sizzler

How do I specify that a DecimalFormat should ALWAYS prepend the decimal sign?

I thought DecimalFormat("-00000.00");

would be ok, But in that case a negative number will start with a double minus:
--0034.56

Is there really no other way than

System.out.println("Number=" + ((number >=0)? "+" : "") + sdf.format(number));

Mark
 
R

Roland

How do I specify that a DecimalFormat should ALWAYS prepend the decimal sign?

I thought DecimalFormat("-00000.00");

would be ok, But in that case a negative number will start with a double minus:
--0034.56

Is there really no other way than

System.out.println("Number=" + ((number >=0)? "+" : "") + sdf.format(number));

Mark
Use new DecimalFormat("+00000.00;-00000.00")
The part following the ';' is the pattern for negative values (and the
other of course for positive ones). See
<http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html>
--
Regards,

Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top