|
Author |
Topic: float (Read 250 times) |
|
gabon
|
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
|
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
|
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
|
|
|
|
|