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

just66horns

macrumors newbie
Original poster
May 6, 2009
21
0
Denver CO
Hi.

I want to display in my apps view the results of a calculation, in a UILabel.

The calculations are being handled as floats. The error I am getting is
"Incompatible type for argument 1 of setText:"

What am I doing wrong... I know it is related to mishandling of the variable type. How do I get the float to display in the UILabel as xx.x (one digit after the decimal?).

Code:
-(BOOL) textFieldShouldReturn: (UITextField *) textFeildA{
	[textFeildA resignFirstResponder];
	if (moveViewUp) [self scrollTheView:NO];
	float a = [textFieldA.text floatValue];
	float b = [textFieldB.text floatValue];
	float fy = a / b;  
	[self updateDisplay:fy];
	return YES;
}
- (IBAction) updateDisplay: (float) e
{
	[labelAoverB setText: e];
}

Thanks!
 

just66horns

macrumors newbie
Original poster
May 6, 2009
21
0
Denver CO
hmmm

OK, I don't get it.
How can I take a float, and convert it to use for the string required for the setText of a UILabel?
Please, more help required.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State

just66horns

macrumors newbie
Original poster
May 6, 2009
21
0
Denver CO
OK, I get it... Thanks

this worked... My syntax is still poor...
Code:
-(BOOL) textFieldShouldReturn: (UITextField *) textFeildA{
	[textFeildA resignFirstResponder];
	if (moveViewUp) [self scrollTheView:NO];
	float a = [textFieldA.text floatValue];
	float b = [textFieldB.text floatValue];
	float fy = a / b;  
	[self updateDisplay:fy];
	return YES;
}
- (IBAction) updateDisplay: (float) e
{
	[labelAoverB setText:[NSString stringWithFormat:@"%.01f",e]];
}
 

ChOas

macrumors regular
Nov 24, 2006
139
0
The Netherlands
Ah, then they probably would want to use something like @"%0.1f". (Maybe that's what you meant?)

Actually I meant %.1f, somehow I was thinking of 0-leading ints.

(probably from the xx part (good band, btw))

Anyways, for precision 01 an 1 are the same, so no harm done.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.