Rounding

From Noop
Jump to: navigation, search

The most useful method at programming contests and for practiceit.

public static String round(double number, int place){

	return new BigDecimal(number + "").setScale(place, RoundingMode.HALF_UP).toString();

}

Example

round(3.333, 1) returns 3.3.

round(3.335, 2) returns 3.34.