I want to display double
number with +/- sign and I am using this decimal format for that
double d = 0;
DecimalFormat nf = new DecimalFormat("+#0.0;-#0.0");
System.out.println(nf.format(d));
d = -1;
System.out.println(nf.format(d));
d = 1;
System.out.println(nf.format(d));
and I am getting out-put like this
+0.0
-1.0
+1.0
but I want 0.0
without +
sign like
0.0
-1.0
+1.0
Thanks
As with this, I'm not entirely sure there is a way to solve this with only decimal format, however a slight modification of the regex given in that answer (Again, Credit: @Bohemian) seems to solve the problem.
This simply looks for numbers in the format of the number 0 (i.e 0 followed by some number of zeros after a decimal point), removing the sign preceding it.