Re: NSDecimalNumber and 10.2.x: is this bug a secret?
Re: NSDecimalNumber and 10.2.x: is this bug a secret?
- Subject: Re: NSDecimalNumber and 10.2.x: is this bug a secret?
- From: Stéphane Sudre <email@hidden>
- Date: Mon, 1 Mar 2004 14:16:03 +0100
On lundi, mars 1, 2004, at 10:22 AM, Stiphane Sudre wrote:
On lundi, mars 1, 2004, at 05:55 AM, Louis C. Sacha wrote:
That way the object is an NSNumber instead of an NSDecimalNumber, and
the CFNumber equivalent works correctly for writing out to the plist.
Of course, it only works for values within the ranges of these types,
and if you don't know the exact type of number being entered you
would probably need to default to using float for the conversion.
The long answer: The following is what happens when an NSDictionary
is written out to a file in 10.2.6 (as a plist), although the process
is probably similar for other system versions. When the dictionary is
written out to a file, it goes through this process for each of the
objects:
[...]
Yes it's fixed in 10.3, but it's not going to help a lot. I think I
will try to make the NSDecimalNumber to NSNumber conversion myself
before writing the object to a .plist since I can't trust the API.
Just for the record, this is the workaround I'm using (not too clever,
but not too dumb either). I filed a bug against this (there's no record
of the 10.3 fix in the CoreFoundation release notes).
@implementation NSDecimalNumber (FixPList)
+ (id) convertObjectToNSNumberIfNeeded:(id) aObject
{
if ([aObject isMemberOfClass:[NSDecimalNumber class]]==YES)
{
double tValue;
double tRoundValue;
NSNumber * tNumber;
tValue=[((NSDecimalNumber *) aObject) doubleValue];
tRoundValue=floor(tValue);
if (tValue==tRoundValue)
{
long long tFlooredValue;
tFlooredValue=(long long) tRoundValue;
tNumber=[NSNumber numberWithLongLong:tFlooredValue];
}
else
{
tNumber=[NSNumber numberWithDouble:tValue];
}
return tNumber;
}
return aObject;
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.