-
Notifications
You must be signed in to change notification settings - Fork 63
Fix decimal place in bits_to_name #99
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
Conversation
There appears to be a quirk with the round method that it will show the number as a float if you specify 0 decimal places and as an int if you don't specify the places at all. This tweak should fix the issue.
jeffkala
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
netutils/bandwidth.py
Outdated
| if val["low"] <= speed < val["high"]: | ||
| try: | ||
| return f"{round(speed / val['low'], nbr_decimal)}{bit_type}" | ||
| if nbr_decimal != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep it a bit more dry, does this make sense?
if nbr_decimal == 0
nbr_decimal = None
>>> round(1500 / 100, None)
15
>>> round(1500 / 100, 0)
15.0
>>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I've refactored this bit to remove duplication and simplify it.
| {"sent": {"speed": 1000000000, "nbr_decimal": 1}, "received": "1.0Gbps"}, | ||
| {"sent": {"speed": 1000000000000}, "received": "1.0Tbps"}, | ||
| {"sent": {"speed": 1000000000000}, "received": "1Tbps"}, | ||
| {"sent": {"speed": 1000000000000, "nbr_decimal": 1}, "received": "1.0Tbps"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add one example of a non-zero?
There appears to be a quirk with the round method that it will show the number as a float if you specify 0 decimal places and as an int if you don't specify the places at all. This tweak should fix the issue. refactor: ♻️ Simplify code to reduce code duplication
This PR addresses issue #85. There appears to be a quirk with the round method that it will show the number as a float if you specify 0 decimal places and as an int, if you don't specify the places at all. This tweak should address the quirk and represent the name as expected.