iphone - doubleValue does not convert the object to a double value correctly at all times -


I have an NSArray in which I would like to store double values. I have defined it

  NSMutableArray * setOfDoubles;   

I add elements as follow

  NSNumber * num; Number = [nsnumber number double: something repeating]; [SetOfDoubles addObject: num];   

And I follow the element

  num = [setOfDoubles lastObject]; [Remove SetOfDoubles] Double Values ​​+ [Number Double Value];   

My problem sometimes occurs (for example), for example when num (in the form of object) is 5.1, double value to u (as a double value) 5.099999999999996. The way I figured out the number (in the form of the object), it's 5.1 that I debug and when I'm hovering over the mouse at the number num = [setOfDoubles lastObject] on the mouse; It shows 5.1. But after double value conversion I mentioned this number. Does anyone know why this is happening?

Each number can not be accurately displayed by using float variables. For example, You can not represent the correct digits in our normal decimal (base-10) system, say, 1/3, but in Ternary (Base-3), it will be just 0.1. Similarly, numbers can be written in numbers with a number of digits, not necessarily a finite number of digits in their binary representation, so error.

Some links on the topic if you are interested:



Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -