diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-11-17 21:28:33 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-11-17 21:28:33 +0100 |
commit | e3cd49d353941624a08d3c79b8da32b106bfd742 (patch) | |
tree | a75641160448454845460ad6b4e64974879351cf | |
parent | b4c164ad8eb27a25c9b2eacf1c3bb94e5c188df2 (diff) |
-fix rouding
m--------- | contrib/gana | 0 | ||||
m--------- | contrib/wallet-core | 0 | ||||
-rw-r--r-- | src/lib/exchange_api_stefan.c | 28 |
3 files changed, 18 insertions, 10 deletions
diff --git a/contrib/gana b/contrib/gana -Subproject 22ef218ba8da81d60b5fb1fa641c86ec20a09a3 +Subproject 27de076550489d6ca0b99822121579e02fee4cf diff --git a/contrib/wallet-core b/contrib/wallet-core -Subproject 4cfef06e890f1e556027c9e294a9c7736ec1ecb +Subproject 621dad2c2ec9a2adc52076cebf65891d6764c80 diff --git a/src/lib/exchange_api_stefan.c b/src/lib/exchange_api_stefan.c index 6f6c3f2c7..226bca82f 100644 --- a/src/lib/exchange_api_stefan.c +++ b/src/lib/exchange_api_stefan.c @@ -299,22 +299,30 @@ TALER_EXCHANGE_keys_stefan_round ( struct TALER_Amount *val) { const struct TALER_Amount *min; - uint32_t mod = 1; + uint32_t mod; uint32_t frac; - uint32_t rst; + uint32_t lim; + if (0 == val->fraction) + { + /* rounding of non-fractions not supported */ + return; + } min = get_unit (keys); if (NULL == min) return; - frac = min->fraction; - while (0 != frac % 10) + if (0 == min->fraction) + { + frac = TALER_AMOUNT_FRAC_BASE; + } + else { - mod *= 10; - frac /= 10; + frac = min->fraction; } - rst = val->fraction % mod; - if (rst < mod / 2) - val->fraction -= rst; + lim = frac / 2; + mod = val->fraction % frac; + if (mod < lim) + val->fraction -= mod; /* round down */ else - val->fraction += mod - rst; + val->fraction += frac - mod; /* round up */ } |