Gavin Andresen - 2011-02-24 02:39:59

@s{quotedtext} @s{quotedtext}
Converting from a double-precision float from the JSON library to an int64 bitcoin is:
Code:
int64 nAmount = roundint64(dAmount * COIN);
... which will always do the right thing (COIN is 100000000).

int64 to JSON string there are no code changes.

GUI string to int64 is a direct conversion, no intermediate double precision.

And int64 to GUI string is:
Code:
strprintf("%.08f", double(amount)/double(COIN))
... which also always does the right thing (printf of a floating point number rounds, and there is enough precision in a double the rounding will always be correct).

0.1 bitcoins will always become exactly 10000000 base units internally, and 10000000 base units will always be shown as exactly 0.10 (in the GUI) or 0.10000000 (in JSON).