Albert
Albert

Reputation: 29

iOS Game Center submit time elapsed

I'm trying to submit a double with the time that the user took to beat a stage. The leaderboard score format type is "Elapsed time - To the hundredth of a second". Something like this:

0:11:44.09

So I have a double that says the time is 11.734929 (it's 0:11:73). I multiply it to 6000 to convert it to int64_t. The result is 70409.572494. I can only send and int64_t so I'm losing 0.572494 seconds. The time sent is finally 0:11:44.09.

How can I send the full time instead of part of it?

EDIT:

I found the solution:

double my_time = ...

double intPart = 0;
double fractPart = modf(my_time, &intPart);
int isecs = (int)intPart;
int min = isecs / 60;
int sec = isecs % 60;
int hund = (int) (fractPart * 100);

int64_t time_to_send_through_game_center = min*6000 + (sec*100 + hund);

Upvotes: 2

Views: 1690

Answers (1)

ColdLogic
ColdLogic

Reputation: 7275

Not sure if this is what you are asking.

If you want 70409572.494 to be able to send 70409572, then multiply by 6000000 instead of 6000. This will convert 11.734929 to 70409572.494

Upvotes: 1

Related Questions