Convert value to fractional inch

Convert value to fractional inch

thomasa88
Advocate Advocate
425 Views
2 Replies
Message 1 of 3

Convert value to fractional inch

thomasa88
Advocate
Advocate

Hi, the following function can convert values between different units:

adsk.core.Application.get().activeProduct.fusionUnitsManager.convert(2.54, "cm", "inch")

 

That works well, but now I want to convert a value to a fractional inch, say 3.25" to 3 1/4". How can I do that?

0 Likes
Accepted solutions (1)
426 Views
2 Replies
Replies (2)
Message 2 of 3

JeromeBriot
Mentor
Mentor
Accepted solution

Hello,

 

I don't know if something exists in the API, but in Python you can do this:

import fractions
val_dec = 3.25
val_frac = fractions.Fraction(val_dec)
print("{} {}".format(int(val_dec), val_frac % 1))
Message 3 of 3

BrianEkins
Mentor
Mentor

I can confirm that there is nothing in the API to get fractions.  Thanks to @JeromeBriot for pointing out there is something in the Python library.  I wasn't aware of that.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com