NSDecimalNumber学习记录

NSDecimalNumber是NSNumber的子类,不可变,提供一个面向对象的方式来做十进制运算.是一个wrapper,我猜是有相应的CF函数的.一个实例可以表示任何数字在这个范围内(mantissa x 10^exponent)

> mantissa 定点部分  exponent 指数

定点部分是一个十进制数,最高38位;指数是一个整数,从-128到127.

iOS 2.0+
macOS 10.0+
tvOS 9.0+
watchOS 2.0+

Important

The Swift overlay to the Foundation framework provides the Decimal
structure, which bridges to the NSDecimalNumber class. The Decimal
value type offers the same functionality as the NSDecimalNumber
reference type, and the two can be used interchangeably in Swift code
that interacts with Objective-C APIs. This behavior is similar to how
Swift bridges standard string, numeric, and collection types to their
corresponding Foundation classes.

For more information about value types, see Classes and Structures in
The Swift Programming Language (Swift 3.0.1) and Working with Cocoa
Frameworks in Using Swift with Cocoa and Objective-C (Swift 3.0.1).

Creating a Decimal Number

++ decimalNumberWithDecimal:
快速创建一个十进制,参数是一个NSDecimal结构体
+ decimalNumberWithMantissa:exponent:isNegative:
用一个u long long定点数,一个short指数,一个bool正负
+ decimalNumberWithString:
自己看文档
+ decimalNumberWithString:locale:

Initializing a Decimal Number

  • initWithDecimal:
  • initWithMantissa:exponent:isNegative:
  • initWithString:.
  • initWithString:locale:

Performing Arithmetic(算法)

  • decimalNumberByAdding:
  • decimalNumberBySubtracting: (减法)
  • decimalNumberByMultiplyingBy:
  • decimalNumberByDividingBy:
  • decimalNumberByRaisingToPower:(幂)
  • decimalNumberByMultiplyingByPowerOf10:
    Multiplies the receiver by 10^power and returns the product, a newly created NSDecimalNumber object.
    余下的方法是上面的方法附带一个withBehavior:参数

Rounding Off 四舍五入

  • decimalNumberByRoundingAccordingToBehavior:

Accessing the Value

decimalValue
The decimal number’s value, expressed as an NSDecimal structure.
doubleValue
The decimal number’s closest approximate double value.
- descriptionWithLocale:

Comparing Decimal Numbers
- compare:
比较

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值