您好我正在尝试为我的应用设置本地化,它目前从文本框中接收字符串,并将它们转换为双精度。然后它继续进行计算并将其作为字符串输出到屏幕上
我想要做的是,让应用程序知道他们来自特定国家/地区将字符串转换为当地货币,进行计算,然后以相关货币输出,
我认为解决方案在于nsformatter。我一直在查看文档,但我迷路了,这是我的代码,你们有什么建议欢迎任何帮助。
(IBAction)calculateCost:(UIButton *)sender {
NSString *rate = self.textField1.text;
NSString *wat = self.textField2.text;
NSString *hours = self.textField3.text;
NSString *Days = self.textField4.text;
double num1 = [rate doubleValue];
double num2 = [wat doubleValue];
double num3 = [hours doubleValue];
double num4 = [Days doubleValue];
double appKw = num2 / 1000;
double costKwph = appKw *num1;
double tCost = ((num4 * num3) * costKwph);
if (num2 == 0 || num1 == 0 || num3 == 0 || num4 == 0) {
self.textField5.text = 0;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"oops" message:@"you must fill in all fields" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil];
[alert show];
}
tCost = tCost / 100;
self.textField5.text = [NSString stringWithFormat:@"£%0.2f",tCost];
}