如何从 TextField 获取十进制值并在 Objective C 中用它进行计算
How to get decimal value from TextField and make calculations with it in Objective C
我是 objective c 的新手,我在文本字段及其值方面遇到了一些问题。我的 ViewController 中有两个 TextField。使用这些 TextFields,我试图获取用户的体重和身高并计算他们的 Body 质量指数。我已经在 android 中编写了下面的代码,并尝试将其转换为 objective c .
valueWeight = Double.parseDouble(edit_txt_weight.getText().toString());
valueHeight = Double.parseDouble(edit_txt_height.getText().toString());
resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.setText(new DecimalFormat("##.##").format(resulBMI)+"");
我的问题是;
如何从文本字段(键盘类型为小数键盘)获取值并将其转换为十进制数。
如何在 objective c 中进行计算,当我使用此代码从文本字段获取值时遇到一些问题
- (IBAction)btnCalculate:(id)sender {
NSString *weight = self.editTextKg.text;
NSString *height = self.editTextHeight.text;
}
- (IBAction)btnCalculate:(id)sender {
double weight = [ self.editTextKg.text doubleValue]
double height = [ self.editTextHeight.text doubleValue];
double resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.text = [NSString stringWithFormat:@"%.2f",resulBMI];
}
我是 objective c 的新手,我在文本字段及其值方面遇到了一些问题。我的 ViewController 中有两个 TextField。使用这些 TextFields,我试图获取用户的体重和身高并计算他们的 Body 质量指数。我已经在 android 中编写了下面的代码,并尝试将其转换为 objective c .
valueWeight = Double.parseDouble(edit_txt_weight.getText().toString());
valueHeight = Double.parseDouble(edit_txt_height.getText().toString());
resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.setText(new DecimalFormat("##.##").format(resulBMI)+"");
我的问题是;
如何从文本字段(键盘类型为小数键盘)获取值并将其转换为十进制数。
如何在 objective c 中进行计算,当我使用此代码从文本字段获取值时遇到一些问题
- (IBAction)btnCalculate:(id)sender {
NSString *weight = self.editTextKg.text;
NSString *height = self.editTextHeight.text;
}
- (IBAction)btnCalculate:(id)sender {
double weight = [ self.editTextKg.text doubleValue]
double height = [ self.editTextHeight.text doubleValue];
double resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.text = [NSString stringWithFormat:@"%.2f",resulBMI];
}