开发者

TextField text to float (Objective-C)

How do I convert the text ins开发者_运维技巧ide of a TextField to a float in Objective-C?


float myFloat = [[myTextField text] floatValue];

Edit: technically the most proper way to do this would be to use an NSNumberFormatter, since that will return a nil NSNumber if it can't parse the string properly, whereas floatValue will just return 0.0 for a malformed string. But floatValue is usually adequate for most purposes.


If it's an NSTextField you call floatValue on the actual object, not on what's returned from text. NSTextField does not have a text method.

float myFloat = [myTextField floatValue];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜