iDevGames Forums
Can't use NSString to put a number on screen? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Can't use NSString to put a number on screen? (/thread-4869.html)



Can't use NSString to put a number on screen? - kensuguro - Oct 27, 2005 11:51 AM

I'm trying to put up a number, a float to be exact, on a custom view. It's part of a simple animation loop using NSTimer, but anyhow, I can't think of a way to use make NSMutableString accept a number.

I understand for arrays and such, I can use NSNumber numberWithFloat:0.0 to convert to an object, but NSNumber doesn't have the displaying functionality that NSMutableString has.(like NSString)

So, how do I convince NSMutableString to accept the float (or any number)? I can do normal text just fine. Or there's a different way to do it without going through NSMutableString's drawing method? I'm guessing it's one of those fundamental things a newbie like myself has to ask.. it's probably too basic people don't even write about it.


Can't use NSString to put a number on screen? - OneSadCookie - Oct 27, 2005 12:12 PM

Code:
+[NSMutableString stringWithFormat]



Can't use NSString to put a number on screen? - kensuguro - Oct 27, 2005 12:16 PM

got it. thanks. I kept on bangin' the setString: method, no wonder it didn't work. Is that method inherited from NSString? cuz I dont' see it in the NSMutableStrings list.. oh well, classes are cool, but things are so hard to comprehend when I'm still learning the class hiarchy.


Can't use NSString to put a number on screen? - Jordan - Nov 7, 2005 01:16 AM

Code:
void floatToString
{
     float     aFloat = 3.14;
     NSNumber * myNum;
     NSString * myStringFloat;

     myNum = [NSNumber numberWithFloat:aFloat];

     myStringFloat = [NSString stringWithString:[myNum stringValue]];

     NSLog(@"Converted value:  %s", [myStringFloat cString]);
}