Select Page
Latest 0.2.0 https://github.com/amisare/NNDecimalNumber MIT ios 7.0, requires ARC Haijun Gu

# NNDecimalNumber

## 使用

• 示例一：全部使用 NSNumber 计算
``````    //( ( ( 3 + 2 + 5 ) × 3 ) × ( 10 × 2 ) )
• 示例二：全部使用 NSString 计算
``````    //( ( ( 3 + 2 + 5 ) × 3 ) × ( 10 × 2 ) )
• 示例三：使用 NSNumber 与 NSString 混合计算
``````    //( ( ( 3 + 2 + 5 ) × 3 ) × ( 10 × 2 ) )
• 示例四：幂运算
``````    {
//( ( 2 × 5 + ( 2 × 2 ) ) ^ 2 )
}
{
//( ( 2 × 5 + ( 2 × 2 ) ) × 10 ^ 2 )
}``````
• 示例五：数值比较
``````    NSString *c0 = @"100";
NSNumber *c1 = @(100.1);
if ([c0 nn_decimalIsEqualTo:c1]) {
NSLog(@"c == c1");
}
else if ([c0 nn_decimalIsGreaterThan:c1]) {
NSLog(@"c > c1");
}
else if ([c0 nn_decimalIsGreaterThanOrEqualTo:c1]) {
NSLog(@"c >= c1");
}
else if ([c0 nn_decimalIsLessThan:c1]) {
NSLog(@"c < c1");
}``````
• 示例六：异常计算（异常计算结果统一为字符串：@"NaN"，即`[[NSDecimalNumber notANumber] stringValue]`
``````    //( 2 × [UIView new] )
NSString *c = @"2".nn_mul([UIView new]);
NSLog(@"%@", c); //打印值：NaN``````
• 示例七：计算式输出
``````    //( ( ( 3 + 2 + 5 ) × 3 ) × ( 10 × 2 ) )
NSLog(@"%@", c.nn_formula); //打印值：( ( ( 3 + 2 + 5 ) × 3 ) × ( 10 × 2 ) )``````

## 安装

### CocoaPods

``\$ gem install cocoapods``

`podfile` 中添加：

``pod 'NNDecimalNumber', '~> 0.1.0'``

``\$ pod install``

``[!] Unable to find a specification for `NNDecimalNumber```

``pod install --repo-update``

## 其他

Inspiration RLArithmetic

### Latest podspec

```{
"name": "NNDecimalNumber",
"version": "0.2.0",
"summary": "Implement NSDecimalNumber calculations on NSString, NSNumber Category, simplifying NSDecimalNumber calculations.",
"description": "Implement NSDecimalNumber calculations on NSString, NSNumber Category, simplifying NSDecimalNumber calculations.",
"homepage": "https://github.com/amisare/NNDecimalNumber",
"type": "MIT",
},
"authors": {
"Haijun Gu": "[email protected]"
},
"social_media_url": "http://www.jianshu.com/users/9df9f28ff266/latest_articles",
"source": {
"git": "https://github.com/amisare/NNDecimalNumber.git",
"tag": "0.2.0"
},
"platforms": {
"ios": "7.0"
},
"requires_arc": true,
"source_files": "NNDecimalNumber/NNDecimalNumber/*.{h,m}",