public static String shorten(float f, int decimals) {
    if (Math.abs(f) < 0.1f) return "0" ;
    final boolean neg = f < 0 ;
    if (neg) f *= -1 ;
    final int i = (int) f ;
    final float r = f - i ;
    if (r == 0) return ""+i ;
    final String fraction = r+"" ;
    final int trim = Math.min(decimals + 2, fraction.length()) ;
    return (neg ? "-" : "")+i+(fraction.substring(1, trim)) ;
  }