OK, so you are editing the text field using the numeric keypad, which depends on the current locale and thus gets a text representation of the number, which also depends on the current locale. After editing is complete, you will read it and want to convert to a number.
For conversion, you should use NSNumberFormatter as follows:
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
, , (!), , , /, .. :
float number = [nf numberFromString: field.text];
! , , : , - , .
, :
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setNumberStyle: NSNumberFormatterCurrencyStyle];
[nf setRoundingMode: NSNumberFormatterRoundHalfUp];
[nf setMaximumFractionDigits: 2]
4 :
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setNumberStyle: NSNumberFormatterPercentStyle];
[nf setRoundingMode: NSNumberFormatterRoundHalfUp];
[nf setMaximumFractionDigits: 4];
.
, , , , , . ( NSNumberFormatter), Apple, SO-, .
, , paino pituus UITextFields:
-(IBAction)calculate {
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setRoundingMode: NSNumberFormatterRoundHalfUp];
[nf setMaximumFractionDigits: 2];
float npaino = [[nf numberFromString: paino.text] floatValue];
float npituus = [[nf numberFromString: pituus.text] floatValue];
float x = npaino] / npituus *10000;
label.text = [nf stringFromNumber: [NSNumber numberWithFloat: x]];
[nf release];
}
, , , .