Objective-C学习笔记NSNumber和数据类型转换

/ 0评 / 0

NSNumber和数据类型转换

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
//        // insert code here...
//        NSLog(@"Hello, World!");
        NSNumber *boolNumber = [NSNumber numberWithBool:YES];
        NSNumber *charNumber = [NSNumber numberWithChar:'A'];
        NSNumber *intNumber = [NSNumber numberWithInt:1];
        NSNumber *floatNumber = [NSNumber numberWithFloat:2.718];
        NSNumber *doubleNumber = [NSNumber numberWithDouble:3.14];
        bool boolValue = [boolNumber boolValue];
        char charValue = [charNumber charValue];
        int intValue = [intNumber intValue];
        float floatValue = [floatNumber floatValue];
        double doubleValue = [doubleNumber doubleValue];
        NSLog(@"boolValue:%d\ncharValue:%c\nintValue:%d\nfloatValue:%f\ndoubleValue:%f\n",boolValue,charValue,intValue,floatValue,doubleValue);
    }
    return 0;
}

 

感谢您的认真阅读。

发表评论

电子邮件地址不会被公开。 必填项已用*标注