'How to convert <class 'UnitsNet.Ratio'> to a float type number for calculations?

When I call a function via my company's API, I get a result which looks like a float number - for example 0.38

However, the type of these numbers are Ratio objects with the type UnitsNet.Ratio. I cannot multiply these values together, this is the error message I get when I try to do so:

TypeError: No method matches given arguments for op_Multiply: (<class 'UnitsNet.Ratio'>)

This is what I can see in the _init.py file for the API:

**@property
    def LoadAnalyse(self) -> Ratio:**

Could anyone let me know how to convert the Ratio object into a floating number? I have tried converting it into a float, but I get the following error message:

TypeError: float() argument must be a string or a number, not 'Ratio'



Solution 1:[1]

You can't just convert an object to a primitive type like that, unless it represents a primitive type, then the repr function in it's python class would maybe work. Check the documentation and check if that class has a function or public member that gets the primitive representation as either a float, or string to parse.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 acornTime