Getting 'nan' when inserting method in stringWithFormat

I have simplifed some methods for ease of understanding and correction of the error. I get a 'nan' instead of getting the number and don't understand why. I want to put the getNumber method inside the return statement. When I have the method inside it returns a string of nan but when I just put the 26 inside it returns 26, what I want.

-(double) getNumber { return 26; }

-(NSString *) convertToString {
        return [NSMutableString stringWithFormat: @"%Lf",[self getNumber]];
// returns 'nan'           when I replace [self getNumber] with 15 I get 15


You might want to use "%f" instead of "%Lf", since you are passing a double, not a long double

You have a couple problems in your code.

  1. Return a double, not an integer in getNumber. While automatic coercion will occur, write clean code.
  2. Use the %g format specifier, not %Lf. %g is for doubles.

It's your format specifier. You should use "%g" to format a double.

Need Your Help

@Transactional not working with spring and hibernate

hibernate spring transactions annotations

I am trying to do spring transactions with @Transactional without any success.

php curl remote upload to rapidshare

php curl upload rapidshare

this is a simple function to upload files remotely via php to rapidshare, requires username and password and curl activated in your server.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.