f

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

```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

```
 0
marksiz (11)
2/21/2005 7:17:27 PM
comp.lang.java.programmer 52714 articles. 1 followers.

2 Replies
430 Views

Similar Articles

[PageSpeed] 59

```On 21-2-2005 20:17, Mark Sizzler wrote:
> 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_/ /__/
/  \ /_/ /  \
```
 0
roland31 (393)
2/21/2005 8:01:49 PM
```In message <cvdc47\$tik\$05\$1@news.t-online.com>,
Mark Sizzler wrote on Mon, 21 Feb 2005 20:17:27 +0100:

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

DecimalFormat df = new DecimalFormat( ... );
df.setPositivePrefix( "+" );

--
Cheers, Tilman

`Boy, life takes a long time to live...'      -- Steven Wright
```
 0
2/21/2005 8:03:37 PM