The Crazy Chimp The Crazy Chimp - 1 year ago 91
Objective-C Question

Objective c division of two ints

I'm trying to produce a a float by dividing two

s in my program. Here is what I'd expect:

1 / 120 = 0.00833

Here is the code I'm using:

float a = 1 / 120;

However it doesn't give me the result I'd expect. When I print it out I get the following:


Answer Source

Do the following

float a = 1./120.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download