Wednesday, 15 September 2010

objective c - Dividing variables of type long long to get a percentage? -


So I'm trying to split two variables that has long been , < Code> totalBytesWritten and totalBytesExpected

Actually I am trying to remove the percentage of the completion of my file upload and according to the progress bar I am updating. For example, I am sending 262144 to 1821948 bytes

But when I do double progress = estimated total bytes / total bytes approximate then gives me some unexpected number When I progress to NSLog I get only 0s and finally 1.

Thank you!

If you are dividing an integer, the result is going to double, but it's too late It's gone: You've already lost the precision. If you repeat one of the two operators, one will be encouraged to double the other and you will get a floating point value as a result:

  NSLog (@ "% F, "(double) total bits written / total bytes expected);    

No comments:

Post a Comment