Fix wrong round definitions in runtime

This commit is contained in:
Denis Merigoux 2022-03-17 13:09:57 +01:00
parent f312c6bc6a
commit a3e9dfa534
No known key found for this signature in database
GPG Key ID: EE99DCFA365C3EE3
2 changed files with 4 additions and 3 deletions

View File

@ -101,7 +101,8 @@ let money_to_cents m = m
let money_round (m : money) : money =
let units, cents = Z.div_rem m (Z.of_int 100) in
(* If [m] is negative, [cents] will also be negative. *)
if Z.(abs cents < of_int 50) then units else Z.(units + of_int (sign units))
if Z.(abs cents < of_int 50) then Z.(units * of_int 100)
else Z.((units + of_int (sign units)) * of_int 100)
let decimal_of_string (d : string) : decimal = Q.of_string d
let decimal_to_float (d : decimal) : float = Q.to_float d

View File

@ -369,9 +369,9 @@ def money_to_cents(m: Money) -> Integer:
def money_round(m: Money) -> Money:
res, remainder = t_divmod(m, 100)
if remainder < 50:
res
return res * 100
else:
res + sign(res)
return (res + sign(res)) * 100
# --------
# Decimals