Closed nayuta-ueno closed 5 years ago
JSON-RPC(listunspent) return BTC amount by string. jansson library use strtod() to convert double value to integer. After convert, the value need round off.
listunspent
strtod()
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <inttypes.h> #define VALUES "20999991.99978481" int main(void) { double val = strtod(VALUES, NULL); printf("%20.8lf\n", val); printf(" %20.10lf\n", val); // NG "2099999199978480" printf("%" PRIu64 "\n", (uint64_t)(val * (uint64_t)100000000)); // OK "2099999199978481" printf("%" PRIu64 "\n", (uint64_t)(val * (uint64_t)100000000 + 0.5)); return 0; }
JSON-RPC(
listunspent
) return BTC amount by string. jansson library usestrtod()
to convert double value to integer. After convert, the value need round off.