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 › division that returns a value less than one
Page Index Toggle Pages: 1
division that returns a value less than one (Read 250 times)
division that returns a value less than one
Aug 5th, 2008, 9:53pm
 
Whenever I perform division that returns a value less than one, processing returns zero.  Even if I use float, it returns 0.0.  For example:

void draw(){
 print(1/2);
 noLoop();
}

returns 0, rather than .5.  What's up?
Re: division that returns a value less than one
Reply #1 - Aug 5th, 2008, 11:44pm
 
You're dividing integers, not floating point numbers. When you have an integer on both the top and bottom, it returns an integer, that is a whole number.

If you want numbers with decimal points in, either the top or bottom needs to be a float (IIRC, might be just the bottom) so what you want is:

Code:
void draw()
{
println(1/2);
println(1/2.0);
println(1.0/2);
println(1.0/2.0);
}
Page Index Toggle Pages: 1