You can create an NSNumber object with double value by calling NSNumber
initWithDouble method. NSNumber is an general container object for any number(integer, float, double...). Note that NSNumber
initWithDouble method begins with "init" as its method prefix, so the returned object is not auto-released. You should release the NSNumber object when you are done with the object. [NSNumber
initWithDouble example]
#import <Foundation/Foundation.h>
int
main(
int
argc,
char
*argv[])
{
NSAutoreleasePool *pool = [NSAutoreleasePool
new
];
NSNumber *objNum;
NSInteger n;
objNum = [NSNumber numberWithInt:100];
n = [objNum integerValue];
NSLog(@
"n:%i"
,n);
objNum = nil;
objNum = [[NSNumber alloc]initWithDouble:0.7];
NSLog(@
"number:%f"
, [objNum doubleValue]);
[objNum release];
[pool drain];
return
0;
}