Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Unsafe calculations in converting interest rates to whole numbers #397

Closed
purplesmoke05 opened this issue Sep 29, 2022 · 0 comments · Fixed by #398
Closed

[BUG] Unsafe calculations in converting interest rates to whole numbers #397

purplesmoke05 opened this issue Sep 29, 2022 · 0 comments · Fixed by #398
Assignees
Labels
bug Something isn't working

Comments

@purplesmoke05
Copy link
Member

purplesmoke05 commented Sep 29, 2022

Describe the bug

if data.interest_rate is not None:
_interest_rate = int(data.interest_rate * 10000)

Rounding errors would be occur at this point.
(When multiplying by 10000 in Python, this is not a problem because the error is upward. Currently, this does not cause any bugs.)

この箇所で丸め誤差が生じる可能性がある。
(Python上で10000で掛け算を行う場合、誤差が上方向になるため、特に問題にならず、現状もバグが起こることはない。)

Reproduction code

from decimal import Decimal
for i in range(1000000):
    input=Decimal(i)*Decimal(0.0001)
    output=float(input)*10000
    if i != int(output):
            print("This isn't shown")

Expected behavior

Use decimal in multiply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants