I have been browsing through the most upvoted questions on Stack Overflow and noticed there is a bug in the number of upvotes for the most popular one:
At least on the Android app instead of 11k only 1.1k are displayed.
As of v1.0.82 (beta), it has been fixed. The app now shows the vote count properly.
1,1k is according to my knowledge 1100. But when opening the question it shows a vote count of 11089 which is way more than 1,1K. The correct display value would be 11k or 11,1k (with rounding).
Note that my phone locale is Dutch. Which means that points are used for separating thousands and commas decimals.
Method one: decimal point when the K postfix is used and the number is shorter than 3 digits.
public static String format(int votes){
// Without K
if(votes < 10000){
return String.format("%,d", votes);
}
// K + 1 decimal
else if(votes < 100000){
return String.format("%,.1fK", votes/1000.0);
}
// Just K
return String.format("%,dK", votes/1000);
}
Result:
1043 > 1.043
11089 > 11,1K
100000 > 100K
1000000 > 1.000K
Method two: no decimals at all (my favorite).
public static String format(int votes){
if(votes < 10000){
return String.format("%,d", votes);
}
return String.format("%,dK", votes/1000);
}
Result:
1043 > 1.043
11089 > 11K
100000 > 100K
1000000 > 1.000K
7,690
), it seems the error is in the rounding logic.