Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Currency/Swift/currency.swift
Normal file
19
Task/Currency/Swift/currency.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Foundation
|
||||
|
||||
extension Decimal {
|
||||
func rounded(_ scale: Int, _ roundingMode: NSDecimalNumber.RoundingMode) -> Decimal {
|
||||
var result = Decimal()
|
||||
var localCopy = self
|
||||
NSDecimalRound(&result, &localCopy, scale, roundingMode)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
let costHamburgers = Decimal(4000000000000000) * Decimal(5.50)
|
||||
let costMilkshakes = Decimal(2) * Decimal(2.86)
|
||||
let totalBeforeTax = costMilkshakes + costHamburgers
|
||||
let taxesToBeCollected = (Decimal(string: "0.0765")! * totalBeforeTax).rounded(2, .bankers)
|
||||
|
||||
print("Price before tax: $\(totalBeforeTax)")
|
||||
print("Total tax to be collected: $\(taxesToBeCollected)")
|
||||
print("Total with taxes: $\(totalBeforeTax + taxesToBeCollected)")
|
||||
Loading…
Add table
Add a link
Reference in a new issue