Re: NSString floatValue issue
Re: NSString floatValue issue
- Subject: Re: NSString floatValue issue
- From: Randall Meadows <email@hidden>
- Date: Tue, 26 Feb 2008 11:11:06 -0700
On Feb 26, 2008, at 10:55 AM, C Sandeep wrote:
Greetings,
I need to evaluate a NSString as a float value (represented by
NSNumber object). Here is my code snippet:
----
NSString *str = @"28/5";
NSNumber *nm = [NSNumber numberWithFloat:[str floatValue]];
NSLog(@"number: %@", nm );
----
this results in:
----
number: 28.0
Right. NSNumber won't evaluate the arithmetic expression, it'll only
convert a string representation of a number, stopping when it finds
something that's not part of a number (in this case, the "/"). You'll
need to do the evaluating yourself.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden