Java Data Type How to - Left left justify a float point value format








Question

We would like to know how to left left justify a float point value format.

Answer

import java.util.Formatter;
/*from   ww w .  j  a  v  a2 s  . co  m*/
public class MainClass {
  public static void main(String args[]) {
    Formatter fmt = new Formatter();

    fmt.format("|%-10.2f|", 123.123);
    System.out.println(fmt);
  }
}

The code above generates the following result.