5

Observation

While browsing trough the most up-voted questions in the mobile app (Stack Overflow) I noticed that questions with a vote count higher than 10.000 are displayed wrong or at least in a way I don't understand.

screenshot

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  
1
  • You should probably post the fix as answer in the question I linked and mark this one as dupe.
    – nicael
    Commented Jun 28, 2015 at 23:06

0

Browse other questions tagged .