开发者

How to add two textField value

开发者 https://www.devze.com 2022-12-31 21:48 出处:网络
I want to take two textfields values and add the values and show them into another textField. How todo this programatically开发者_开发问答?Follow this tip, then add the two NSNumbers.

I want to take two textfields values and add the values and show them into another textField.

How to do this programatically开发者_开发问答?


Follow this tip, then add the two NSNumbers.

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * myNumber = [f numberFromString:ftext];
NSNumber * myNumber2 = [f numberFromString:ftext2];

float out = [myNumber floatValue] + [myNumber floatValue];
[f autorelease];

-dan


There is also a floatValue method on NSString so you can also do something like:

float sum = [textField1.text floatValue] + [textField2.text floatValue];

Which is a little more concise.

0

精彩评论

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

关注公众号