There\'s been a lot of questions on rounding by significant figures, and answers that that provides a new method to do the rounding, such as:
Rounding to an arbitrar
Not quite right. To get it perfect:
public String toSignificantFiguresString(BigDecimal bd, int significantFigures ){
String test = String.format("%."+significantFigures+"G", bd);
if (test.contains("E+")){
test = String.format(Locale.US, "%.0f", Double.valueOf(String.format("%."+significantFigures+"G", bd)));
}
return test;
}