需要在Objective-C编写的计算器 [英] Need to write calculator in Objective-C

查看:280
本文介绍了需要在Objective-C编写的计算器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给些建议的算法使用或您的解决方案,以解决一些问题是这样的:

  //一些字符串
的NSString * S = @5 *(2.56-1.79)-4.1;
 

解决方案

您可以做:

  NSEx pression * EX pression = [NSEx pression EX pressionWithFormat:秒]。
float结果= [[EX pression EX pressionValueWithObject:无背景:无]的floatValue]。
的NSLog(@%F,结果);
 

Give some advice which algorithm use or your solution, to solve some problem like this:

//Some string
NSString *s = @"5*(2.56-1.79)-4.1";

解决方案

You can do as:

NSExpression *expression = [NSExpression expressionWithFormat:s];
float result = [[expression expressionValueWithObject:nil context:nil] floatValue];
NSLog(@"%f", result);

这篇关于需要在Objective-C编写的计算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆