C# 如何为两个文本字段、多个标签和一个按钮添加不同的计算
我使用文本字段供用户输入数据,并使用标签在计算数据后显示数据。 当我将这两个文本字段相乘时,它可以完美地工作。但是,当我引入更多的标签时(我需要两个文本字段与不同的公式关联,以生成13个不同的标签),它会干扰最初的两个标签,并且数学不起作用 这段代码可以工作:C# 如何为两个文本字段、多个标签和一个按钮添加不同的计算,c#,xcode,C#,Xcode,我使用文本字段供用户输入数据,并使用标签在计算数据后显示数据。 当我将这两个文本字段相乘时,它可以完美地工作。但是,当我引入更多的标签时(我需要两个文本字段与不同的公式关联,以生成13个不同的标签),它会干扰最初的两个标签,并且数学不起作用 这段代码可以工作: float floatHeightResult=[rectWidth.text floatValue] * [rectLength.text floatValue]; NSString *stringHeightResult=[[NSS
float floatHeightResult=[rectWidth.text floatValue] *
[rectLength.text floatValue];
NSString *stringHeightResult=[[NSString alloc]
initWithFormat:@"%1.2f",floatHeightResult];
heightResult.text=stringHeightResult;
但是,一旦我引入其他添加项,如以下内容,它就不起作用了:
float floatWeightResult=[rectWidth.text floatValue] +
[rectWidth.text floatValue] * 2.87 ;
NSString *stringWeightResult=[[NSString alloc]
initWithFormat:@"%1.2f",floatWeightResult];
widthResult.text=stringWeightResult;
如何将这两个数字相加,然后将结果乘以另一个数字 //我想这对你会有帮助的
float fl_rectWidth = [rectWidth.text floatValue];
float fl_rectLength = [rectLength.text floatValue];
float floatHeightResult = fl_rectWidth * fl_rectLength;
lbl_heightResult.text=[NSString stringWithFormat:@"%1.2f",floatHeightResult];
float floatWeightResult = fl_rectWidth + floatHeightResult ;
lbl_widthResult.text=[NSString stringWithFormat:@"%1.2f",floatWeightResult];