Skip to content

Conversation

@fonglh
Copy link
Contributor

@fonglh fonglh commented Apr 3, 2023

This prevents other rounding bugs and comparison errors caused by the inability of floats to store base 10 numbers precisely.

Add a test to hack.py to demonstrate the rounding error from using float.

Why:

Existing solution does not resolve rounding errors and incorrect comparisons caused by using the float type for base 10 calculations.

What's being changed:

Convert item amounts to Decimal.
Add test case to hack.py to demonstrate the comparison problem.
Add explanation in solution.py with link to Python's Decimal documentation as well as examples from the Python interpreter.

fonglh and others added 2 commits April 3, 2023 15:24
This prevents other rounding bugs and comparison errors caused by
the inability of floats to store base 10 numbers precisely.

Add a test to hack.py to demonstrate the rounding error from using
float.
@jkcso jkcso requested review from cmwilson21 and heiskr April 3, 2023 18:38
@jkcso jkcso mentioned this pull request Apr 3, 2023
@jkcso jkcso merged commit 2b1d6b7 into skills:main Apr 3, 2023
bgalek added a commit to bgalek/secure-code-game-fork that referenced this pull request May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants