使用双精度值作为 GKLeaderboard 的分数?

发布于 2024-11-07 18:31:43 字数 89 浏览 6 评论 0原文

我想知道是否有办法在 GKLeaderboard 上使用双精度值?它坚持要求我使用int64_t,但我需要使用双精度值,因为排行榜是最快的时间,计数到小数点后六位。

I wondered if there's a way of using a double value on GKLeaderboard? It insists that I use int64_t, but I need double values to be used, as the leaderboard is for the fastest time, counting to six decimal points.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放低过去 2024-11-14 18:31:43

由于您需要一个小到百万的十进制数,一种解决方案是简单地乘以 1,000,000 并强制转换为 int64_t

int64_t intScore = (int64_t)1000000 * doubleScore;

然后当您得到分数时:

double doubleScore = (double)intScore / 1000000;

Since you need a decimal number down to the millions, one solution would be to simply multiply by 1,000,000 and coerce to an int64_t:

int64_t intScore = (int64_t)1000000 * doubleScore;

Then when you get the score back:

double doubleScore = (double)intScore / 1000000;
感悟人生的甜 2024-11-14 18:31:43

如果您以微秒精度进行测量,则可以将单位设置为微秒而不是秒。然后你可以使用整数。

(同样,金钱永远不应该表示为浮点值,而应该表示为代表您想要考虑的最小金额的整数值 - 因此 1 美元将是 100(美分)而不是 1.0(美元)。)

If you're measuring with microsecond precision, you can just have the units be microseconds instead of seconds. Then you can use integers.

(Similarly, money should never be represented as a floating-point value, but as an integral value representing the smallest amount of money you want to consider — so a dollar would be 100 (cents) rather than 1.0 (dollars).)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文