Here you can find the source of shorten(double num)
public static String shorten(double num)
//package com.java2s; //License from project: LGPL import java.text.DecimalFormat; public class Main { public static String shorten(double num) { String string = Double.toString(num); if (Integer.parseInt(string.split("\\.")[1]) == 0) { return string.split("\\.")[0]; } else {//from w w w . j a va 2 s .c om DecimalFormat format = new DecimalFormat("0.##"); return format.format(num); } } }