Limit the number of decimal digits by specifying the precision
import java.util.Formatter; public class Main { public static void main(String[] argv) throws Exception { Formatter fmt = new Formatter(); fmt.format("Default precision: %f\n", 10.0 / 3.0); fmt.format("Two decimal digits: %.2f\n\n", 10.0 / 3.0); System.out.println(fmt); } }