We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Here is my program:
size(300,300); background(255); fill(0);
float a, b;
a = 575 * 2 / 100; b = 575 / 100 * 2;
text(str(a),10,20); text(str(b),100,20); println(a); println(b);
I should read 11.5 and 11.5, but i read 11 and 10. I guess a rounding using "/100", but why i just want to divide by 100. I guess something very simple behind that weird calcul error, but i can't find it !
Thank you
Answers
https://forum.Processing.org/two/discussion/13417/problem-with-making-a-window-size-scale
Integer division, it's an FAQ
It shoulda been in the
/
division operator's reference itself: X(https://Processing.org/reference/divide.html
Sorry, i can imagine it is a FAQ, as it is very simple and basic point, and the reference of /divide on processing.org says nothing about that.
ok, so we just need to add a ".", it works, but i still find that strange, looks like a specificity of JAVA and C... why not. I am worried, i need to check all my old programs !
Thank you wasted hours on that!
Just for completeness' sake, suffixing any number literal w/
f
ord
also forces it to become "fractional":575 * 2 / 100f;
;)Also any literal using scientific notation is automatically fractional too:
575 * 2 / 1e2;
:-BP.S.: Learn how to format code for the forum too: B-)
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
Yes, got it, will use the tags so far, thanks
You also can use 100.0 instead of 100f