var total: NSDecimalNumber = NSDecimalNumber.zero
let price1: NSDecimalNumber = 10
let price2: NSDecimalNumber = 5
total = price1.adding(price2)
var price: NSDecimalNumber = NSDecimalNumber.zero
let price1: NSDecimalNumber = 10
let price2: NSDecimalNumber = 5
price = price1.subtracting(price2)
let price: NSDecimalNumber = 10
let count: NSDecimalNumber = 5
let total: NSDecimalNumber = price.multiplying(by: count)
let total: NSDecimalNumber = 20
let price: NSDecimalNumber = 5
let count: NSDecimalNumber = total.dividing(price)
/*
public enum RoundingMode : UInt {
case plain // Round up on a tie
case down // Always down == truncate
case up // Always up
case bankers // on a tie round so last digit is even
}
*/
let round = NSDecimalNumberHandler(roundingMode: NSDecimalNumber.RoundingMode.bankers, scale: 2, raiseOnExactness: false, raiseOnOverflow: false, raiseOnUnderflow: false, raiseOnDivideByZero: true)
let orginPrice: NSDecimalNumber = 999.9999
let disCount: NSDecimalNumber = 0.75
let price = orginPrice.multiplying(by: disCount, withBehavior:round)
let price1: NSDecimalNumber = 10
let price2: NSDecimalNumber = 5
let result: NSComparisonResult = price1.compare(price2)
if result == NSOrderedAscending {
} else if result == NSOrderedSame {
} else if result == NSOrderedDescending {
}
let count: NSDecimalNumber = 5
let total: NSDecimalNumber = count.raising(toPower: 2)
网友评论