Java examples for Language Basics:Number Format
Using floating-point conversion characters.
public class Main { public static void main(String[] args) { //from w w w .j av a 2s . com System.out.printf("%e\n", 12345678.9); System.out.printf("%e\n", +12345678.9); System.out.printf("%e\n", -12345678.9); System.out.printf("%E\n", 12345678.9); System.out.printf("%f\n", 12345678.9); System.out.printf("%g\n", 12345678.9); System.out.printf("%G\n", 12345678.9); } }