I\'m trying to separate the decimal and integer parts of a double in swift. I\'ve tried a number of approaches but they all run into the same issue...
let x:
Swift 5.1
let x:Double = 1234.5678 let decimalPart:Double = x.truncatingRemainder(dividingBy: 1) //0.5678 let integerPart:Double = x.rounded(.towardZero) //1234
Both of these methods return Double value.
if you want an integer number as integer part, you can just use
Int(x)