I am currently making an application in Swift 2 for OS X where I have a variable called x
, of type double, that I do not know what it is. What I want to do with this variable x
is to get the decimal value and store it as an int.
This is what I want to do:
var x:Double = some random value
var xdp:Int = decimal part of x
To make it easier to understand, say my variable x
is 72.535
, I would want variable xdp
to be 535
. So far I have been able to x%1
which gives me 0.535
using this example, I could then times that by 1000 which will give me 535
(which is what I want), however if that value was 0.53
, I would end up getting 530
which is 10 times bugger then what I want.
How would I be able to get the decimal value using swift 2 for OS X?
Sorry if this is hard to understand, I wasn't sure how to say it. If this is hard to understand, please tell me and I will try my best to re-word it.