Let's say I have a value representing 1927. Now I want to get the last 2 digits of the specified year. Is there an efficient way to do this in Swift? So far, I have figured out the following method based on my SO study:
// My goal is to start with 1927 and end with 27
let fullYear = 1927 as Float //
let valueToSubtract = Int(fullYear/100) //
let splitNumber = fullYear/100 as NSNumber //
let decimalValue = Float(splitNumber) - Float(valueToSubtract) //
let finalNumber = Double(round(1000 * decimalValue)/10) //
It seems too cumbersome. I'm new to programming and Swift, have I missed an easier way?
source
share