Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func convert(_ textValue: String) -> Int{
- var total = 0
- var valueMap = [
- "1" as Character: 1,
- "2": 2,
- "3": 3,
- "4": 4,
- "5": 5,
- "6": 6,
- "7": 7,
- "8": 8,
- "9": 9,
- "0": 0
- ]
- for (i, c) in textValue.enumerated() {
- let exponent = textValue.count - i - 1
- if let value = valueMap[c] {
- let num = Decimal(value) * pow(10, exponent)
- total += NSDecimalNumber(decimal: num).intValue
- }
- }
- return total
- }
Add Comment
Please, Sign In to add comment