How to convert string to nsnumber in objective c?



How to convert string to nsnumber in objective c?..

Answer / Km. Arti

To convert a string to an NSNumber object in Objective-C, you can use the following code:
```objectivec
NSString *yourString = @"42";
NSNumber *number = [yourString numberWithInteger:[yourString integerValue]]; // for integer values
// For floating point numbers:
double yourDouble = 3.14;
NSString *yourStringDouble = [NSString stringWithFormat:@"%f", yourDouble];
NSNumber *numberDouble = [yourStringDouble numberWithDouble:yourDouble];
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Objective-C Interview Questions

What is #import?

1 Answers  


What are the blocks? How will you use them?

1 Answers  


Is objective c the same as c++?

1 Answers  


Is swift objective c?

1 Answers  


Explain the way messaging works in objective-c?

1 Answers  


Can a static library (.a) contain resources like images, sound files etc?

1 Answers  


What is property and its types?

1 Answers  


Explain what do you mean by synthesized in objective-c?

1 Answers  


What is an objective statement?

1 Answers  


What are objective c properties?

1 Answers  


What is mark and sweep algorithm?

1 Answers  


What do you mean by @synthesize and @dynamic in the objective-c? And also explain what do you mean by synthesized in objective-c?

1 Answers  


Categories