Can someone explain me this NSString behavior ?

  • (IBAction) numPadClicked: (id)sender {
    NSString *newVal;
    NSLog(@“Appending %@ to %@”, [sender title],[outerCalculation stringValue]);
    newVal = [[outerCalculation stringValue]stringByAppendingString:[sender title]];
    NSLog(@“giving %@”, newVal);
    [outerCalculation setStringValue:newVal];
    }

I typed “7.5”, each character calls the IBAction:

2012-05-16 02:21:01.905 Evals7[6844:403] Appending 7 to
2012-05-16 02:21:01.906 Evals7[6844:403] giving 7
2012-05-16 02:21:03.300 Evals7[6844:403] Appending . to 7
2012-05-16 02:21:03.300 Evals7[6844:403] giving 7.
2012-05-16 02:21:04.898 Evals7[6844:403] Appending 5 to 7
2012-05-16 02:21:04.899 Evals7[6844:403] giving 75

Where is the dot gone between line 4 and 5 of the logs?

I can’t explain it – I made outerCalculation a text field and had 3 buttons whose titles were “5”,“7”, and “.” and I copied and pasted your code. I didn’t get what you got – I got what you would expect.

Ric

I guess there is a number formatter attached to the text field.
With an international number format using a comma as decimal separator and the default number formatter setting the result of [textField setStringValue:@“7.5”] is “75”

“Elementary,” said he.

That’s right, Stefan. I didn’t expect this singular behavior. I just wanted it to put a leading zero if the user typed “.5”, as on a usual calculator (and I didn’t succeed).

Well, I’m really impressed!

Thank you!

Edit: I unchecked the “localize” option and everything is working fine now.