0

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

How to do this programatically?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
mukeshpawar
  • 125
  • 2
  • 3
  • 9

2 Answers2

1

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

Community
  • 1
  • 1
Daniel Blezek
  • 4,539
  • 1
  • 19
  • 20
1

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.

Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88