Can't use NSString to put a number on screen?

Post: #1
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.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
+[NSMutableString stringWithFormat]
Quote this message in a reply
Post: #3
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.
Quote this message in a reply
Post: #4
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]);
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Malloc() Struct with NSString Inside? Graphic Ace 3 6,815 Jan 26, 2010 05:32 PM
Last Post: mysteriouspants
  What do you want to see in a Random Number Generator? Justin Brimm 16 12,232 Jan 21, 2007 10:38 AM
Last Post: Justin Brimm
  Getting Number From Character In NSString Nick 2 5,989 Oct 31, 2005 10:08 AM
Last Post: Nick
  Even Number of Triangles for Any 3D model unknown 1 4,143 Sep 21, 2005 08:34 AM
Last Post: Zekaric
  random number Kaamoss 14 9,342 May 13, 2005 03:03 AM
Last Post: DoG