java string format rounding code example Example 1: java string format .2f String.format("%.2f", 3.45); Example 2: java format double no decimal places int x = (int) y