Is there a way to get the value after the decimal point out of a double variable?
doubleVar = 234.045
Can i get only the .045 out of the variable?
Is there a way to get the value after the decimal point out of a double variable?
doubleVar = 234.045
Can i get only the .045 out of the variable?
Divide the double by 1 using truncatingRemainder(dividingBy:) and get the reminder.
var doubleVar = 234.045
var new = doubleVar.truncatingRemainder(dividingBy: 1.0)
let rounded = Double(round(1000*new)/1000)
print(rounded)
OR
Using C function modf
var doubleVar = 234.045
let splitPi = modf(doubleVar)
splitPi.0 // 324.0
splitPi.1 // 0.045
I don't know swift but integer truncation should help. Something like
let doubleVar = 234.045
let result = doubleVar - Int(doubleVar)