20

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:

shiny image of this bug

At least on the Android app instead of 11k only 1.1k are displayed.

2
  • Repro'd on Nexus 5, Lollipop 5.1.1, SE app v1.0.68. Considering that the app can display the second most upvoted question without being cut (7,690), it seems the error is in the rounding logic. Commented Jul 14, 2015 at 1:58
  • @AndrewT. I believe the problem is in the number of digits. This is the only question above 10k Commented Jul 14, 2015 at 4:32

2 Answers 2

2

As of v1.0.82 (beta), it has been fixed. The app now shows the vote count properly.

it is 13k!

1
  • Beat me to the punch, thanks Andrew!
    – Kasra Rahjerdi StaffMod
    Commented Jan 21, 2016 at 19:04
1

Expected behavior

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.

Proposed fix

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  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .