Java: How to round a double (or float) to two decimal places? (formatting output)Use DecimalFormat or String.format to round double and float values to two decimal places.Remember precision loss with float values due to fewer bits than double.