We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! The problem I've is: When I make a division (using float) the result is always getting 0 decimals. I mean, let's say I've this:
float a = 10.25; float b = 123/12;
It should be exactly the same but, if I make a display the result would be a=10.25 (that's ok) and b = 10.0 Why processing is not capable of work with the full number? I got the same result with every division, for instance 1/10 is always 0.0
Thanks a lot!!
Answers
@v13duran --
It is performing integer division because you specified two integers, then divided them. 10 is the number of whole times that 12 goes into 123. Instead try:
Okey, I got it. I must write: float b = 123.0/12.0;
Without .0 it's not going to work...
Writing ".0" makes a value a float, as you say. You can get a fractional division answers by making:
Only int/int gives integer division answers.
You may also be interested in this past discussion of rounding: