i want to sum to values which i get from a textfiel. how can i cast a textfield value in double value ?
Regards Caglar
i want to sum to values which i get from a textfiel. how can i cast a textfield value in double value ?
Regards Caglar
See this question: How to do string conversions in Objective-C?
double myDouble = [myTextField.text doubleValue];
You can use doubleValue
to convert a NSString (from your text field) to a double like so:
double myDouble = [myTextField.text doubleValue];
This isn't a cast, by the way, it's a conversion. The doubleValue
method performs a conversion from a string to a double representation. Casts are something you can only perform on primitive numeric types or pointers in Objective-C.
convert text entered in textfield to integer
double mydouble=[_myTextfield.text doubleValue];
rounding to the nearest double
mydouble=(round(mydouble));
rounding to the nearest int(considering only positive values)
int myint=(int)(mydouble);
converting from double to string
myLabel.text=[NSString stringWithFormat:@"%f",mydouble];
or
NSString *mystring=[NSString stringWithFormat:@"%f",mydouble];
converting from int to string
myLabel.text=[NSString stringWithFormat:@"%d",myint];
or
NSString *mystring=[NSString stringWithFormat:@"%f",mydouble];