I have a double, which is the time interval in seconds. Allowed values: 0.0, 0.5, 1.0, 1.5, etc.
Now I need to convert this value to int. But I can not do this:
int converted = (int)theDouble;
Because it may happen that my double due to floating point errors is 0.999999999, not 1.000000000. It would just cut off the tail, and we would end with 0 instead of 1. Also, when my double is 0.9, I want int to be 1. When it is 1.1, I want int to be 1. When it is 1, 8, I want int to be 2.
There is a round () function there, but Xcode does not show the documentation for this. The header reports that it returns double. So not what I need.
What is the safest way to get a close inner view of this double? Although this is double, I will never need a higher accuracy than 0.5 or a single fragmentary figure (I am not a mathematical genius and I do not know the exact scientific terms).
source
share