I am using below method to convert number in formatted way like
private static String coolFormat(double n, int iteration) {
double d = ((long) n / 100) / 10.0;
boolean isRound = (d * 10) %10 == 0;//true if the decimal part is equal to 0 (then it's trimmed anyway)
return (d < 1000? //this determines the class, i.e. 'k', 'm' etc
((d > 99.9 || isRound || (!isRound && d > 9.99)? //this decides whether to trim the decimals
(int) d * 10 / 10 : d + "" // (int) d * 10 / 10 drops the decimal
) + "" + c[iteration])
: coolFormat(d, iteration+1));
}
How it can be result for two decimal point.
Log.e("PrintValue ", coolFormat(1520,0)+"");
06-01 15:57:07.625 19542-19542/? E/PrintValue: 1.5k
If i will enter 1520 OUTPUT=> 1.5k but output should be 1.52k