Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hintzsche

macrumors newbie
Original poster
Jul 28, 2009
25
23
hi i tried to programming a app on iphone, but i got the following errors

double input = [inputTextField doubleValue]; !incompatible types in initialization
double factor = [factorTextField doubleValue]; !incompatible types in initialization
double result = input * factor;
[outputTextField setdoubleValue:result]; !UITextField may not respaont on -setdoubleValue

can someone help me ?
 
Try:
Code:
double input = [inputTextField.text doubleValue];
double factor = [factorTextField.text doubleValue];
double result = input * factor;
outputTextField.text = [NSString stringWithFormat:@"%f", result];
 
Thanks but now i got the problem that the user cant type a ,

because the programm dont count with , now
only with .

what can i do to make a . from a ,

and i got more then 2 nubers after the . but i only need 2 nubers after the ,

can someone help me ?
 
Thanks but now i got the problem that the user cant type a ,

because the programm dont count with , now
only with .

what can i do to make a . from a ,

and i got more then 2 nubers after the . but i only need 2 nubers after the ,

can someone help me ?

Are you referring to a numerical value separated by commas?
As in "500,000" or something similar?

Try grabbing the text as a string and removing the commas...alternatively im sure there is an apple function *somewhere* to convert a number into a string including commas and the like. Try looking at the NSString class reference.
 
yes i try to create a money convertion programm. and the user will type 1,35$
are 1,00 € but when he do this the programm dont recognise the numbers after the ,

and if the user use a . the result will be 1.3500000

that will confuse the user :)

so what is the solution of this problem ?
 
According to the Class Reference for NSString, doubleValue:
This method uses formatting information stored in the non-localized value; use an NSScanner object for localized scanning of numeric values from a string.
 
NSScanner

No, it's still NSScanner, as it's part of the Foundation Framework.

Code:
- (IBAction)calculate:(id)sender
{
	double input = [inputTextField.text doubleValue];
	double factor = [factorTextField.text doubleValue];
	
	double result = input * factor;
	[outputTextField setText:[NSString stringWithFormat:@"%f",result]];
}

This is the code i wrote where i cant use a , and where the result was 1.3400000


where do i have to place the NSScanner ?
 
do you mean NSScanner input = [inputTextField.text doubleValue];

or do you mean double input = [inputTextField.text NSScanner];

???

do i have to do something more ?
 
I believe that you can use NSNumberFormatter numberFromString to parse float values in a locale-dependent manner.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.