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 10:22:17 +0100
On lundi, mars 1, 2004, at 05:55 AM, Louis C. Sacha wrote:
Hello...
I can verify that the bug exists in 10.26, although it seems to be a
bug in Core Foundation rather than NSDecimal Number.
The short answer: In 10.2.6 (and probably 10.2.8) the NSDecimalNumber
is being passed across the CF/NS toll-free bridge, and apparently the
value is ripped out of the object directly instead of calling the
CFNumberGetValue() function, so any type of NSNumber other than an
NSCFNumber does not work correctly on the CF side when a plist is
written.
If you are getting this value in a place in your code where you know
the type of number that will be entered, you could do something like
myNumber = [NSNumber numberWithFloat:[textField floatValue]];
myNumber = [NSNumber numberWithInteger:[textField intValue]];
or myNumber = [NSNumber numberWithUnsignedInt:[[textField objectValue]
unsignedIntValue]];
This is the workaround I'm currently using in some parts of the code
where I know the value is an Integer for instance.
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.
Thanks for the info, it gives me an idea on how to work around this.
_______________________________________________
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.