Using Swift 3.
I am finding a lot of strange solutions online for checking if a Decimal object is a whole number. Everything feels far more complicated then it needs
I'm not sure can works in all cases but that maybe a more coincise option
extension Decimal {
static var decimalSeparator: String { return NumberFormatter().decimalSeparator }
var isFraction: Bool {
return self.description.contains(Decimal.decimalSeparator)
}
var isWhole: Bool {
return !isFraction
}
}