diff --git a/compiler/shared_ast/print.ml b/compiler/shared_ast/print.ml index 047ef7f1..6d9fccd3 100644 --- a/compiler/shared_ast/print.ml +++ b/compiler/shared_ast/print.ml @@ -980,8 +980,10 @@ module UserFacing = struct aux (Z.abs n) let money (lang : Cli.backend_lang) ppf n = + let num = Z.abs n in + let units, cents = Z.div_rem num (Z.of_int 100) in + if Z.sign n < 0 then Format.pp_print_char ppf '-'; (match lang with En -> Format.pp_print_string ppf "$" | Fr | Pl -> ()); - let units, cents = Z.div_rem n (Z.of_int 100) in integer lang ppf units; Format.pp_print_string ppf (decsep lang); Format.fprintf ppf "%02d" (Z.to_int (Z.abs cents)); diff --git a/tests/test_money/good/literal_parsing.catala_en b/tests/test_money/good/literal_parsing.catala_en index 5e174fd4..a731f813 100644 --- a/tests/test_money/good/literal_parsing.catala_en +++ b/tests/test_money/good/literal_parsing.catala_en @@ -7,15 +7,15 @@ declaration scope A: scope A: definition x equals $0.15 * 2.0 - definition y equals $0.3 - assertion x = y + definition y equals - $0.3 + assertion x = - y ``` ```catala-test-inline $ catala Typecheck --check-invariants -[RESULT] Invariant typing_defaults checked. result: [25/25] +[RESULT] Invariant typing_defaults checked. result: [27/27] [RESULT] Invariant match_inversion checked. result: [0/0] [RESULT] Invariant app_inversion checked. result: [0/0] [RESULT] Invariant no_return_a_function checked. result: [0/0] @@ -28,11 +28,11 @@ $ catala Typecheck --check-invariants $ catala Interpret -s A [RESULT] Computation successful! Results: [RESULT] x = $0.30 -[RESULT] y = $0.30 +[RESULT] y = -$0.30 ``` ```catala-test-inline $ catala Interpret_Lcalc -s A --avoid-exceptions --optimize [RESULT] Computation successful! Results: [RESULT] x = $0.30 -[RESULT] y = $0.30 +[RESULT] y = -$0.30 ``` diff --git a/tests/test_typing/good/overload.catala_en b/tests/test_typing/good/overload.catala_en index 6efa2bb3..079bf6d3 100644 --- a/tests/test_typing/good/overload.catala_en +++ b/tests/test_typing/good/overload.catala_en @@ -76,7 +76,7 @@ $ catala Interpret -s S [RESULT] o_b = true [RESULT] o_d = [-13 days] [RESULT] o_i = -5 -[RESULT] o_m = $-5.75 +[RESULT] o_m = -$5.75 [RESULT] o_t = 2022-01-24 [RESULT] o_x = 0.142,857,142,857,142,857,14… ``` @@ -86,7 +86,7 @@ $ catala Interpret_Lcalc -s S --avoid-exceptions --optimize [RESULT] o_b = true [RESULT] o_d = [-13 days] [RESULT] o_i = -5 -[RESULT] o_m = $-5.75 +[RESULT] o_m = -$5.75 [RESULT] o_t = 2022-01-24 [RESULT] o_x = 0.142,857,142,857,142,857,14… ```