Re: Comparing NSDecimalNumber to NaN?
Re: Comparing NSDecimalNumber to NaN?
- Subject: Re: Comparing NSDecimalNumber to NaN?
- From: Jonathan Jackel <email@hidden>
- Date: Thu, 28 Aug 2003 21:56:19 -0400
On Thursday, August 28, 2003, at 05:29 PM, Brian Barth wrote:
>
Hi!
>
>
This thing seems so obvious but still I don't get it.
>
What I want to do is simple:
>
I have a TableView and this standard method:
>
>
-(void)tableView: (NSTableView *) listTableView
>
setObjectValue: (NSString*) someText
>
forTableColumn: (NSTableColumn *) column
>
row: (int) rowIndex
>
>
We know that well.
>
I only want to accept numbers as input. I have a NSMutableArray of
>
NSDecimalNumbers as a data source.
>
Now to be sure the user entered some valid data, I first used a
>
delegate
>
method (- (BOOL) control: (NSControl *) control
>
textShouldEndEditing:(NSText *) fieldEditor) which didn't seem to work
>
as
>
the data seemed to be converted into my decimal number before I could
>
get
>
a grip of it.
You'll probably want to subclass NSFormatter to do this.
>
>
Then I wanted at least catch the error in the above mentioned
>
tableView:setObjectValue:forTableColumn:row: method.
>
Here is what I did:
>
>
NSDecimalNumber *entry = [NSDecimalNumber decimalNumberWithString:
>
someText];
>
Which works fine, if I enter garbage I get a NaN.
>
So now my question: How do I check if I got a NaN???
>
I used:
>
if ( [entry compare: [NSDecimalNumber notANumber]] == NSOrderedSame )
>
if ( [entry isEqual: [NSDecimalNumber notANumber]] )
>
if ( [[entry description] isEqualToString: @"Nan"] )
>
All didn't work and the compiler complains: "warning: statement with no
>
effect". Right he is.
>
>
Can't be that hard, can it?
I have, for reasons that escape me now, had success with:
if ([entry isEqualTo:[NSDecimalNumber notANumber]])
Note that it's "isEqualTo" not "isEqual".
But "statement with no effect" makes me suspect there's something more
subtle wrong with your code. Your first two tries ought to work. The
third one probably needs a capital N at the end, but in principle it
should work, too. Perhaps a more complete extract would help.
Jonathan
_______________________________________________
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.