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 › devide the dividend by an higher divisor
Page Index Toggle Pages: 1
devide the dividend by an higher divisor (Read 560 times)
devide the dividend by an higher divisor
Apr 21st, 2007, 4:55pm
 
everytime i want to devide a dividend by an higher divisor i will get as result called "0".

example:
float t;
t = 50/400;
println(t); //print result "0.0"

how can i made the result be correct with decimal places?
thanks in advanced.
Re: devide the dividend by an higher divisor
Reply #1 - Apr 21st, 2007, 5:19pm
 
You need to make sure processing knows that the numbers you're dividing are floats, and not integers.

In your example, even though 't' is a float, 40 and 100 are integers, and so it'll do an integer divide, not a floating point one.

What you need to do is explicitly make one part of the sum a float:

float t=40.0/100;
or
float t=(float)40/100;
Re: devide the dividend by an higher divisor
Reply #2 - Apr 21st, 2007, 7:04pm
 
thank you.
works fine.
Page Index Toggle Pages: 1