你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> NSDecimalNumber學習記載

NSDecimalNumber學習記載

編輯:IOS開發綜合

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:
比擬

【NSDecimalNumber學習記載】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved