Here is a simple code that shows what I think is a bug when dealing with double numbers...
double wtf = 36.76662445068359375000;
id xxx = [NSDecimalNumber numberWithDouble: wtf];
NSString *myBug = [xxx stringValue];
NSLog(@"%.20f", wtf);
NSLog(@"%@", myBug);
NSLog(@"-------\n");
the terminal will show two different numbers
36.76662445068359375000 and
36.76662445068359168
Is this a bug or am I missing something?
if the second number is being rounded, it is a very strange rounding btw...
= = = = = = = = = =
I am editing the original question to include one more WTF bug...
try this:
modify the original number and truncate it on 10 decimal digits... so...
double wtf = 36.76662445068359375000;
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:10];
NSString *valueX = [formatter stringFromNumber:[NSDecimalNumber numberWithDouble:wtf]];
[formatter release];
NSLog(@"%@", valueX);
the answer now is 36.7666244507
now the value is a string with 10 decimal digits... now lets convert it back to double
double myDoubleAgain = [valueX doubleValue];
NSLog(@"%.20f", myDoubleAgain);
the answer is 36.76662445070000018177 ??????
myDoubleAgain has now more digits!!!!