0

我有浮点数,它的值为 30,我从核心数据中获得。

当我使用 NSLog 打印值时,我得到 30。

NSLog(@"The value of float temp is %@", [self.detailItem valueForKey:@"credit"]);

当我通过将 float 转换为 int 来打印值时,每次打印日志时都会得到奇怪的数字和不同的结果:

NSLog(@"The value of float temp is %d", (int)[self.detailItem valueForKey:@"credit"]);

137978864
122273424
4

2 回答 2

2

尝试这个

NSLog(@"The value of float temp is %d", [[self.detailItem valueForKey:@"credit"] intValue]);
于 2013-05-21T00:59:27.973 回答
1

valueForKey 返回一个对象。Coredata 存储 NSNumber 和 NSString 等对象。您可以使用 intValue 进行转换。尝试:

NSLog(@"The value of float temp is %d", [[self.detailItem valueForKey:@"credit"] intValue]);

于 2013-05-21T00:59:33.787 回答