meterwhite / mathstringexpression Goto Github PK
View Code? Open in Web Editor NEWobjective-c计算数学表达(算术表达式)式框架,开发iOS计算器/Framework of analytical math expressions
License: MIT License
objective-c计算数学表达(算术表达式)式框架,开发iOS计算器/Framework of analytical math expressions
License: MIT License
777777*9999999结果是7777769222223.000576
- (NSString *)createResultString:(NSString *)calcuStr{ NSDecimalNumber *decimalResult = [MSParser parserComputeNumberExpression:calcuStr error:nil]; NSInteger decimalNum = 9; NSDecimal decimal = decimalResult.decimalValue; NSDecimal desDecimal; NSDecimalRound(&desDecimal, &decimal ,decimalNum, NSRoundPlain); NSDecimalNumber *result = [NSDecimalNumber decimalNumberWithDecimal:desDecimal]; NSString *res = [result stringValue]; return res; }
例如排列组合C(3,1)或者A(3,3)怎么写?
"SUM(2,6,3, SUM(100,SUM(3,4)) + MAX(6,7)”
0.3-0.2=0.09999999999999998
计算结果为:-0
转JS表达式结果为:((-1)×0)
/**
* 例4 使用JavaScript定义函数
/
NSError errorJSFun;
MSFunctionOperator* opFunJS = [MSFunctionOperator operatorWithJSFunction:@"function And(a, b){return a + b;}" error:&errorJSFun];
[tab setElement:opFunJS];
NSString* jsExpString = @"And(1,1)";//
BOOL allRight = [MSExpressionHelper helperCheckExpression:jsExpString usingBlock:^(NSError *error, NSRange range) {
NSLog(@"%@",error);
}];
if(allRight){
//计算表达式
NSString* computeResult = [MSParser parserComputeExpression:jsExpString error:nil];
NSLog(@"计算结果为:%@",computeResult);
//表达式转JS表达式
NSString* jsExpression = [MSParser parserJSExpressionFromExpression:jsExpString error:nil];
NSLog(@"转JS表达式结果为:%@",jsExpression);
}
最后输出的计算结果为NAN,表达式为(1,1)
算9++这种不完整的表达式时直接就崩溃了
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.