Reputation: 15
I am newbie to Swift 4 / Xcode development still learning almost 2 weeks, and I have problem with hiding / removing .0 from the slider value that I am trying to create. I have attached image and the code that its displayed on the app.What I am trying to do with this code is to show the number on the app without .0 like if its 15000.0 to show only 15000
@IBAction func changeValueCredit(_ sender: Any) {
let fixed = roundf((sender as AnyObject).value / 100) * 100;
(sender as AnyObject).setValue(fixed, animated: true)
inputValue.text = "\(creditNumber.value)" + " $ "
}
Thank you all
Upvotes: 1
Views: 1291
Reputation: 2273
fixed
is a Float
value, so it won't truncate to your desired value.
If you don't want to round it up or down, you can call:
@IBAction func changeValueCredit(_ sender: Any) {
let fixed = roundf((sender as AnyObject).value / 100) * 100;
let truncatedFixed = Int(fixed)
(sender as AnyObject).setValue(truncatedFixed, animated: true)
inputValue.text = "\(creditNumber.value)" + " $ "
}
Upvotes: 0
Reputation: 15248
Convert to Int
to get rid of decimal
numbers,
inputValue.text = "\(Int(creditNumber.value))" + " $ "
Upvotes: 1