From 88d3857a61a0331e798ce5c1677ea519aa742db2 Mon Sep 17 00:00:00 2001 From: Michele Sessa Date: Thu, 15 Sep 2022 12:21:17 +0100 Subject: [PATCH] 1448 fix(sales): remove inconsistency in expected output also clarify why small discrepancies can appear in results --- subjects/sales/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/subjects/sales/README.md b/subjects/sales/README.md index 9a0f49d3..635fc4aa 100644 --- a/subjects/sales/README.md +++ b/subjects/sales/README.md @@ -41,10 +41,12 @@ impl Cart { ### Example ``` -[1.23, 3.12, 23.1]` => `[1.17, 2.98, 22.07] +[1.23, 3.12, 23.1]` => `[1.17, 2.98, 22.06] ``` -Because `1.17 + 2.98 + 22.07` == `0 + 3.12 + 23.1` +Because `1.17 + 2.98 + 22.06` == `0 + 3.12 + 23.1` + +Floats are rounded with a precision of two decimals which can create small discrepancies as per the example above. This is a percentage calculation, and it can be applied to a set of three items. If the client purchases 9 items, they will receive three for free, with the discount applied to all items. @@ -92,7 +94,7 @@ And its output: $ cargo run Store { products: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)] } [1.17, 2.98, 22.06] -Cart { items: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)], receipt: [1.17, 2.98, 22.07] } +Cart { items: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)], receipt: [1.17, 2.98, 22.06] } $ ```