FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   float
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: float  (Read 250 times)
gabon

WWW
float
« on: Sep 2nd, 2004, 1:31pm »

is there any reason why:
 
Code:
float scala= 1/2;
println(scala);

 
gives me 0.0 ?
Am I so stupid?
 
thx guys, chr
 
TomC

WWW
Re: float
« Reply #1 on: Sep 2nd, 2004, 1:39pm »

1 and 2 are integers (ints).  They can only represent whole numbers, and doing arithmetic with them (+, -, *, /) will only give you integer answers.  The fraction part will be thrown away.
 
To do maths with higher precision, try:
 
Code:

// adding the decimal point to an int makes it  
// into a float and enables the extra precision
float scala = 1.0/2.0;  
println(scala);

 
Hope that helps.
 
« Last Edit: Sep 2nd, 2004, 1:41pm by TomC »  
gabon

WWW
Re: float
« Reply #2 on: Sep 2nd, 2004, 1:43pm »

Thx tom... it was that... is a long time that I don't use java so I feel so stupid when I found this obstacles.
 
thank again, chr
 
Pages: 1 

« Previous topic | Next topic »