NSNumber doubleValue returns NaN

As shown in the screenshot below, the nsdt value is approximately 0.033, but the doubleValue method returns NaN. Why doesn't it return 0.033?

 -(void) updateWithDTNSTime:(NSNumber*) nsdt; { double dt = [nsdt doubleValue]; if(isnan(dt)) { printf("nan\n"); } [self updateWithDTime:dt]; } 

+4
source share
1 answer

Check out the code creating the nsdt variable. It should be like this:

 nsdt - [NSNumber numberWithDouble:0.033]; 

You will have 0 if your code looks like this:

 int x = 0.033; NSNumber *test = [NSNumber numberWithDouble:x]; double y = [test doubleValue]; NSLog(@"y= %f", y); 
0
source

Source: https://habr.com/ru/post/1433090/


All Articles