Getting null in debugger while using stringWithFormat

190 Views Asked by At

(null) while converting double to NSString using stringWithFormat

I am using simply stringWithFormat to get the string value of double using %f. But I am getting null. If I use NSString *myString = [NSNumber stringValue]; it works. What is wrong with code shown in attached screenshot? With NSLog

This is actual production code. and because of this issue some time (very rare) I get crash. The fabric crash log shows that adding null value to NSDictionary causing crash. as I am using modern objective C. my question is "How stringWithFormat works?"

1

There are 1 best solutions below

2
Hitesh Surani On

In second Screen shot, You have one unused code.

Please remove this line Then, It will work fine.

[NSString stringWithFormat:@"%f",number];

Hope you it will work for you.