We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › multiplication and division syntax
Page Index Toggle Pages: 1
multiplication and division syntax (Read 925 times)
multiplication and division syntax
Oct 8th, 2006, 8:18pm
 
perhaps this is old news, but i just had an issue with it.  i tried to do this simple algebra:
(8/3)*110=?

should be 293.333(repeating) using standard syntax.

processing is giving me the value
(8/3)*110=220

in order for it to compute properly i must enter
(8*110)/3=293.333

thought i would drop it in the board.
andy
Re: multiplication and division syntax
Reply #1 - Oct 8th, 2006, 8:39pm
 
The problem is that unless you specify otherwise, Java assumes you're using integers for a reason, and so does an integer divide.
If you want to make sure that it doesn't throw the fractional part away, you need to make sure at least one of the parts of the divide is a floating point number, either by adding .0 to the end, or casting it to a float: (float)8 or float(8).
Re: multiplication and division syntax
Reply #2 - Oct 8th, 2006, 8:47pm
 
that certainly worked.  thanks.
andy
Re: multiplication and division syntax
Reply #3 - Oct 9th, 2006, 3:40am
 
http://processing.org/reference/troubleshooting/index.html#integers
Page Index Toggle Pages: 1