Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. let numbers = ["500", "50", "1000"]
  2.  
  3. for num in numbers {
  4. switch num.count {
  5. case 0:
  6. print("0.00")
  7. case 1:
  8. print("0.0" + num)
  9. case 2:
  10. print("0." + num)
  11. default:
  12. var result = num
  13. let dotIndex = num.index(num.endIndex, offsetBy: -2)
  14. result.insert(".", at: dotIndex)
  15. print(result)
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement