Format float number to have Left justification in Java
Description
The following code shows how to format float number to have Left justification.
Example
// w ww .j a v a 2 s .c o m
import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
// Right justify by default
fmt.format("|%10.2f|", 123.123);
System.out.println(fmt);
// Now, left justify.
fmt = new Formatter();
fmt.format("|%-10.2f|", 123.123);
System.out.println(fmt);
}
}
The code above generates the following result.