Numeric conversion utility functions do not account for floating point errors #10875

Closed
opened 2025-12-29 21:37:06 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Mar 11, 2025).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

NetBox Cloud

NetBox Version

v4.2.5

Python Version

3.10

Steps to Reproduce

  1. Attempt to convert feet to meters using the to_meters() utility function:
>>> from utilities.conversion import to_meters
>>> to_meters(30, 'ft')
Decimal('9.144000000000000460964599824')

Expected Behavior

The function should return the clean decimal value 9.144.

Observed Behavior

The returned value includes a floating point error.

The to_grams() utility function is affected as well.

Originally created by @jeremystretch on GitHub (Mar 11, 2025). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type NetBox Cloud ### NetBox Version v4.2.5 ### Python Version 3.10 ### Steps to Reproduce 1. Attempt to convert feet to meters using the `to_meters()` utility function: ```python >>> from utilities.conversion import to_meters >>> to_meters(30, 'ft') Decimal('9.144000000000000460964599824') ``` ### Expected Behavior The function should return the clean decimal value 9.144. ### Observed Behavior The returned value includes a [floating point error](https://docs.python.org/3/tutorial/floatingpoint.html). The `to_grams()` utility function is affected as well.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:37:06 +01:00
adam closed this issue 2025-12-29 21:37:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10875