Oct-27-2020, 08:47 AM
Let me guess. You're converting
The slowest solution is to work with Decimals.
inch
to mm
.The slowest solution is to work with Decimals.
from decimal import Decimal def inch2mm(inch, precision=None): value = float(Decimal(str(inch)) * Decimal("25.4")) # optional rounding if required if precision is not None: value = round(value, precision) return valueAnother trick is to do the calculation with integers instead of floats.
print(33 * 25.4) print(33 * 254 / 10)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!