Reputation: 17591
I have this situation:
I should write in a text field a value in euro. If inside this text field I write "10" I should store in a double value "10.00" or if I write "10,1" I should store in a double "10,10" or if I write "10,23" I should store "10,23"
How can I do it?
Upvotes: 0
Views: 8221
Reputation: 5540
You can use the typecasting like convert string to double value.
Upvotes: 0
Reputation: 2453
If you want to support localized numbers (e. g. user input), -[NSNumberFormatter numberFromString:]
is the way to go. Since this returns an NSNumber
you can get the double value using -[NSNumber doubleValue]
:
NSNumber *number = [numberFormatter numberFromString:inputString];
double doubleValue = [number doubleValue];
Upvotes: 2
Reputation: 4932
This should help:
double val = [[textField text] doubleValue];
Upvotes: 5