Show positive values with a leading + and negative values within parentheses.
import java.util.Formatter;
public class Main {
public static void main(String[] argv) throws Exception {
Formatter fmt = new Formatter();
fmt.format("Default positive and negative format: %.2f %.2f\n", 423.78,
-505.09);
fmt.format("With + and parentheses: %+.2f %(.2f\n", 423.78, -505.09);
System.out.println(fmt);
}
}
Related examples in the same category