I want to display the value of a slider into a label. The label is called rate and the slider is sliderrate, I tried this:
@IBAction func sliderValueChanged(_ sender: UISlider) {
rate.text = String(round(sliderrate.value))
}
Swift's rounding functions return the same type as you put into them. So if you round a Double
, what you get back is still a Double
. To display the rounded number as an integer, convert it to an Int
first:
Int(slidernote.value.rounded())
Alternately, you can use the lround
function from the standard C library, which returns an Int:
import Foundation
lround(slidernote.value)