Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
33*25.4
#5
Let me guess. You're converting 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 value
Another 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!
Reply


Messages In This Thread
33*25.4 - by schascheck - Oct-27-2020, 12:45 AM
RE: 33*25.4 - by deanhystad - Oct-27-2020, 01:09 AM
RE: 33*25.4 - by bowlofred - Oct-27-2020, 01:56 AM
RE: 33*25.4 - by schascheck - Oct-27-2020, 03:38 AM
RE: 33*25.4 - by DeaD_EyE - Oct-27-2020, 08:47 AM
RE: 33*25.4 - by schascheck - Oct-27-2020, 02:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020