Java examples for Language Basics:Number Format
Using the (flag to place parentheses around negative numbers.
public class Main { public static void main(String[] args) {// w ww.ja v a 2 s . c o m System.out.printf("%(d\n", 50); System.out.printf("%(d\n", -50); System.out.printf("%(.1e\n", -50.0); } }