Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-28-2009, 11:14 AM   #1 (permalink)
Eager to Learn Member
iPhone Dev SDK Supporter
 
mkenney's Avatar
 
Join Date: Sep 2009
Posts: 76
mkenney is on a distinguished road
Default NSNumber from a NSString

Another dumb question from me. I can't seem to find a way to easily convert a NSString to a NSNumber. I know I'm making this harder then it needs to be!!
Code:
UITextField *aText;
NSNumber *aNum;

aNum= ??????? [aText text];
The textField will have a number in it representing a dollar and cents amount...

Thanks again for all your help!!

Mark
mkenney is offline   Reply With Quote
Old 11-28-2009, 11:33 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: London
Posts: 226
_sjc_ is on a distinguished road
Default

There doesn't seem to be any way of converting directly, but NSString has a number of value methods (doubleValue, floatValue, intValue, integerValue, longLongValue, boolValue) which you can use as an intermediate stage eg.
Code:
NSNumber  *aNum = [NSNumber numberWithInteger: [[aText text] integerValue]];
__________________
SimCap - Simple iPhone and iPad Simulator screen capture
_sjc_ is offline   Reply With Quote
Old 11-28-2009, 12:02 PM   #3 (permalink)
Eager to Learn Member
iPhone Dev SDK Supporter
 
mkenney's Avatar
 
Join Date: Sep 2009
Posts: 76
mkenney is on a distinguished road
Default

Quote:
Originally Posted by _sjc_ View Post
There doesn't seem to be any way of converting directly, but NSString has a number of value methods (doubleValue, floatValue, intValue, integerValue, longLongValue, boolValue) which you can use as an intermediate stage eg.
Code:
NSNumber  *aNum = [NSNumber numberWithInteger: [[aText text] integerValue]];
I think I might have to use NSNumberFormatter???
mkenney is offline   Reply With Quote
Old 11-28-2009, 12:08 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: London
Posts: 226
_sjc_ is on a distinguished road
Default

Quote:
Originally Posted by mkenney View Post
I think I might have to use NSNumberFormatter???
If the text field contains anything other than digits and a decimal point, yes. If the number is just a dollar value then you can use -floatValue on the string. You may also like to look at NSScanner.
__________________
SimCap - Simple iPhone and iPad Simulator screen capture
_sjc_ is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 461
16 members and 445 guests
7twenty7, AlanFloyd, David-T, iAppDeveloper, imac74, Jaxen66, logan, lovoyl, markuschow, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0