Search code examples
objective-cgame-centerleaderboard

Float as a score in the leaderboard


I have a leaderboard and in itunes connect I selected "Fixed point - to 2 decimals" for this type of leaderboard. My score is a float value for example "12,13134". But If I upload the score in the leaderboard, is displayed only "0.12" in the leaderboard.

Why is my score, consisting of a float value not displayed correctly?

Thanks in advance


Solution

  • Since you are posting a score in the format of a signed 64-bit integer int64_t, the value of your float gets truncated to simply 12. Once that score makes it to the leaderboard, it gets formatted as a fixed-point decimal, with the point located between the positions of hundreds and tens:

    #######.## <<== 64-bit integer
           ^
           |
    Fixed point position
    

    This produces 0.12 output. Similarly, if your score were 121.3134, the displayed value would have been 1.21; 1213.134 would be displayed as 12.13, and so on.

    If you keep your raw score as a float, and format it to 2 decimals in the leaderboard, all you need is to multiply the score by 100.