Hi all I am trying to convert followers number into readable string like Instagram. For that I used below code :
public static String new_format(double number)
{
String[] suffix = new String[]{"","K", "M", "B", "T"};
int MAX_LENGTH = 4;
String r = new DecimalFormat("##0E0").format(number);
r = r.replaceAll("E[0-9]", suffix[Character.getNumericValue(r.charAt(r.length() - 1)) / 3]);
while(r.length() > MAX_LENGTH || r.matches("[0-9]+\\.[a-z]"))
{
r = r.substring(0, r.length()-2) + r.substring(r.length() - 1);
}
return r;
}
But its not giving the right values for example lelepons have 24.2m followers but it is showing 20m. I got this code snipt from here https://stackoverflow.com/a/49405728/9565955