Force minimum number of digits to left and right of decimal point in Java
Description
The following code shows how to force minimum number of digits to left and right of decimal point.
Example
//from www. j a v a 2 s.co m
import java.text.DecimalFormat;
public class Main {
public static void main(String[] argv) throws Exception {
DecimalFormat formatter = new DecimalFormat("0.0E0");
String s = formatter.format(-1234.567); // -1.2E3
System.out.println(s);
}
}
The code above generates the following result.