原始文献 / 论坛帖 / Re: BUG Report: Rounding glitch

Re: BUG Report: Rounding glitch

Bitcointalk · 2010-07-17 16:06:12 UTC

AuthorSatoshi Nakamoto
TitleRe: BUG Report: Rounding glitch
Date2010-07-17 16:06:12 UTC
ForumBitcointalk · 原文

这一定是 getinfo 把结果转成浮点数返回 JSON-RPC 结果时的舍入误差。唯一用浮点数表示金额的地方,就是在 JSON-RPC 里返回值。

1.139999999999 比比特币内部能表示的精度更长。

内部它只能是:
1.13999999 或
1.14000000

1.139999999999 离 1.14000000 比离 1.13999999 近得多,所以它一定是 1.14000000。

代码是这样的:
(double)GetBalance() / (double)COIN.

(我一时想不出简单的修复办法)

英文原文

It must be a rounding error when getinfo converts to floating point to return the JSON-RPC result. The only place where it uses floating point to represent money is returning a value in JSON-RPC.

1.139999999999 is longer than bitcoin can internally represent.

internally, it could only be:
1.13999999 or
1.14000000

1.139999999999 is much much closer to 1.14000000 than 1.13999999, so it must be 1.14000000.

The code is this:
(double)GetBalance() / (double)COIN.

(I can't think of an easy way to fix it at the moment)