Here you can find the source of roundNicely(double dbl)
private static String roundNicely(double dbl)
//package com.java2s; //License from project: BSD License public class Main { private static String roundNicely(double dbl) { long rounded = Math.round((dbl * 100.0)); String result = String.valueOf(((double) rounded) / 100.0); if (dbl < 10) { result = String.valueOf(Math.round(dbl * 100.0) / 100.0); } else if (dbl < 100) { result = String.valueOf(Math.round(dbl * 10.0) / 10.0); } else {/*from ww w .jav a 2s .c om*/ result = String.valueOf(((long) dbl)); } if (result.endsWith(".0")) { result = result.replace(".0", ""); } return result; } }