i am testing python with processing. one of my first scripts was a simple division 13 divided by 2 which should give out the result 6.5 - but in the console there is 6

does anybody know why it seems to be impossible to give out a float number? by default the pure python gives out a float, if it is a division - processing.py doesn’t

thanks for a hinch

1 Like

Take a look here:

*Troubleshooting · processing/processing Wiki · GitHub*

Why does 2 / 5 = 0 instead of 0.4?

This may apply to Processing Python as well.

`:)`

As @glv has already pointed out, division in Jython and in Python 2 is the same as in Java:

If both operands are of integer type, the division’s result got its fractional part removed (truncates).

Workaround is also very similar:

Make sure 1 of the operands is of float type, by adding a decimal point for literals, or using **float()** to convert a variable.

3 Likes

thank you for the hint. it seems, that it is nessesary to write 13.0 / 2 - then it works.

We can even just add the dot w/o the zero: `13. / 2`

or `13 / 2.`

Or in this case, multiply by half: `13 * .5`

1 Like

cool - i just tested it - works perfect

1 Like