Fixes missing minus sign printing for small negative amounts of money (#560)

This commit is contained in:
Louis Gesbert 2024-01-16 12:21:29 +01:00 committed by GitHub
commit 8ed45c2762
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -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));

View File

@ -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
```

View File

@ -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…
```