Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Setting decimal sign ("+" AND "-") in DecimalFormat ? (http://www.velocityreviews.com/forums/t141240-setting-decimal-sign-and-in-decimalformat.html)

Mark Sizzler 02-21-2005 07:17 PM

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


Roland 02-21-2005 08:01 PM

Re: Setting decimal sign ("+" AND "-") in DecimalFormat ?
 
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_/ /__/
/ \ /_/ / \


All times are GMT. The time now is 07:29 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.