0

I'm converting a text to NSNumber and it working fine in the iPad simulator while it is running (null) in the real iPad device. Please where would be my issue?

NSNumberFormatter * f = [[NSNumberFormatter alloc] init];

[f setNumberStyle:NSNumberFormatterDecimalStyle];

NSNumber * myNumber1 = [f numberFromString:[self txtValue1].text];
NSNumber * myNumber2 = [f numberFromString:[dic objectForKey:from?@"in":@"out"]];

float result1 = [myNumber1 floatValue];
float result2 = [myNumber2 floatValue];

NSLog(@"Check the value2 %@ ",myNumber1); //Result (null)
NSLog(@"Check the value3 %f ", result1); //Result "0"

NSLog(@"string1: %@", [self txtValue1].text); //result in iPad device: 1.35
NSLog(@"string2: %@", [dic objectForKey:from?@"in":@"out"]) //result in iPad device: 1.2

NSLog(@"string1: %@", [self txtValue1].text); //result in iPad Simulator: 1.35
NSLog(@"string2: %@", [dic objectForKey:from?@"in":@"out"]) //result in iPad Simulator: 1.2
Luai Kalkatawi
  • 1,492
  • 5
  • 25
  • 51
  • Actually it works fine with both Simulator and iPad Device. Please make sure you have the same code in your project too. – Ilanchezhian Aug 05 '14 at 16:59
  • It would help if you would NSLog the text string in cases in both the simulator and the iPad and add the results to the question. Best bet, create intermediates with the text strings. Intermediates are generally free in release code but make debugging a lot easier. – zaph Aug 05 '14 at 16:59
  • @Aadhira it is exactly the same code. – Luai Kalkatawi Aug 05 '14 at 17:01
  • @Zaph does that helps? I have copied the result to the question. – Luai Kalkatawi Aug 05 '14 at 17:09
  • Add: `NSLog(@"string1: %@", [self txtValue1].text);` and `NSLog(@"string2: %@", [dic objectForKey:from?@"in":@"out"])` for each and add to the question. Without that we can not try to duplicate the error. – zaph Aug 05 '14 at 18:25
  • @Zaph I have did it as you want. I hope it will help us. – Luai Kalkatawi Aug 05 '14 at 22:21
  • "It's exactly the same code". Here's a hint: If it doesn't work, then there's a bug in your code, and since you didn't fix it, it's in a place where you don't expect it. So making assumptions about which part of your code work, when you already know that _something_ that you think would work doesn't work, that's daft. – gnasher729 Aug 05 '14 at 22:36
  • @gnasher729 I don't know if there is a bug or not but it is very strange that it is working on the simulator fine and not working on the iPad device!! Thanks. – Luai Kalkatawi Aug 05 '14 at 22:50
  • Thank you all for the help. – Luai Kalkatawi Aug 06 '14 at 00:36

1 Answers1

0

After I've changed my code type for the NSNumber as @-notation type rather then NSNumberFormatter as mentioned in this topic NSNumber @-notation finally it is started to show the value in the iPad device.

NSNumber * myNumber1 = @([[self txtValue1].text floatValue]);
NSNumber * myNumber2 = @([[dic objectForKey:from?@"in":@"out"] floatValue]);

float result1 = [myNumber1 floatValue];
float result2 = [myNumber2 floatValue];

NSLog(@"Check the value2 %@ ",myNumber1); //Result 1.35 which it should be
NSLog(@"Check the value3 %f ", result1); //Result 1.2 which it should be
Community
  • 1
  • 1
Luai Kalkatawi
  • 1,492
  • 5
  • 25
  • 51