# Gavin Andresen # 2011-02-24 02:39:59 # https://bitcointalk.org/index.php?topic=3786.msg53946#msg53946 @s{quotedtext} @s{quotedtext} @p{brk} Converting from a double-precision float from the JSON library to an int64 bitcoin is: @p{brk} Code: int64 nAmount = roundint64(dAmount * COIN); ... which will always do the right thing (COIN is 100000000). @p{par} int64 to JSON string there are no code changes. @p{par} GUI string to int64 is a direct conversion, no intermediate double precision. @p{par} And int64 to GUI string is: @p{brk} 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). @p{par} 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). @p{par}