Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

How do I get a floating point out of a division in inline script?

It seems like divisions in the inline script are all floor divisions (no decimals) and I was wondering how to make them true divisions (with decimals). I am using OS 3.1.9 and python 2.7.12. I have already read that it is difficult to make true divisions in python two, but I have found some workarounds online and none of them work on my inline script. Any idea what to do? What I have found is:

  1. Get Python 3 division behavior in any given module with the following import at the top:
    from future import division

  2. truediv from the operator module operator.truediv(a, b),

  3. a / (b * 1.0).

  4. a / float(b).

None of them work.

Comments

  • EDIT: I am not sure what I was doing wrong before, but now at least truediv(a, b) works.

  • Hi Andrea,

    Just so that no-one gets confused about this: All of the above options are valid ways to perform a float division in Python 2.

    So if you don't end up with a float, then the reason lies somewhere else. For example, if you set experimental variables (var.my_variable = 1.0), this will automatically change the value to the simplest fitting type. So the float 1.0 will become the int 1. Is that what's going on perhaps?

    Cheers,
    Sebastiaan

  • Yes, I think that this may have been the problem.

    Thank you!

Sign In or Register to comment.