So I\'m trying to figure out how I can get my program to lose the .0 after an integer when I don\'t need the any decimal places.
@IBOutlet weak var numberOf
A more generic way to suppress (only) the .0 decimal place in a string representation of a Double
value is to use NSNumberFormatter
. It considers also the number format of the current locale.
let x : Double = 2.0
let doubleAsString = NumberFormatter.localizedString(from: (NSNumber(value: x), numberStyle: .decimal)
// --> "2"