summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------contrib/gana0
m---------contrib/wallet-core0
-rw-r--r--src/lib/exchange_api_stefan.c28
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 */
}