Link to home
Start Free TrialLog in
Avatar of BabyFace
BabyFace

asked on

Floats

Hi,

I'm using Visual J++,
and I can't seem to get floats working right!
Here's a piece of code:
float f = 150 / 255;
g.drawString(new Float(f).toString,10,10);

It says 0.0
I'm no mathematician but I'm pretty sure that 150/255 isn't 0.

What's wrong?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of sailwind
sailwind

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sailwind
sailwind

Oh yeah, since 150.0 is considered a double in Java. You should do:

double d = 150.0/255.0  


Avatar of BabyFace

ASKER

Thanks for your answer.
Which of the two take up more mem?
I suppose it's double eh?

Thanks again.
int 32 bits
double 64 bits
float 32 bits
long 64 bits