bcalc

cli bitcoin unit calculator
git clone git://jb55.com/bcalc
Log | Files | Refs | README | LICENSE

commit dff28a8da92c38a8b7bf109db5e634cb1ea5838e
parent 6dfcfb85a82532bb66cd5f3647e7ae98c254ab3f
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 23 Dec 2017 16:18:07 -0800

fiat: fix penny amounts

Diffstat:
Mnum.c | 5+++--
Mtest/tests.csv | 1+
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/num.c b/num.c @@ -29,8 +29,9 @@ num_to_msat(struct num *num) { switch (num->unit) { case UNIT_OTHER: if (g_other.unit == UNIT_NONE) error_any(); - return (int64_t)val * (g_other.type == TYPE_FLOAT ? g_other.floatval - : (double)g_other.intval); + double other = 1.0/(g_other.type == TYPE_FLOAT ? g_other.floatval + : (double)g_other.intval); + return (int64_t)(val * BTC * other); case UNIT_MSATOSHI: return (int64_t)val; case UNIT_SATOSHI: diff --git a/test/tests.csv b/test/tests.csv @@ -26,6 +26,7 @@ simple fiat test with bits,--price 15000 --bits,1 fiat,66.66666 bits 1 other @15k is 66.66666 bits,--price 15000 --bits,1 other,66.66666 bits 1 btc/2 should work,--btc -n,1 btc / 2,0.5 60 usd at 25000 in bits,--bits --price 25000,60 fiat,2400 bits +penny usd to msats,--price 20000 --msats,0.01 usd,50000 msat # failing 1 BTC is 15000 usd,--price 15000 --usd,1 btc,15000 USD # needs implementation