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 › floats and decimal places
Page Index Toggle Pages: 1
floats and decimal places (Read 367 times)
floats and decimal places
Mar 20th, 2008, 7:18pm
 
This question might be better directed at a java forum but here goes:

Where does the following code output 0.0 rather than 0.1?

int a = 100;
int b = 1000;
float i;

i = (a/b);

println(i);
Re: floats and decimal places
Reply #1 - Mar 20th, 2008, 8:30pm
 
try
Code:

i=float(a)/float(b);


or

Code:

i=a/float(b);



Its because Java is a strongly-typed language, so int/int = int.
Page Index Toggle Pages: 1