Reputation: 129
currently my slider looks like this
I want to change the number of current position in a format without decimal place. So in this case it should show me 27 instead of 0.2731...
here is my Code
@Composable
fun Slider() {
var sliderPosition by remember { mutableStateOf(0f) }
Slider(value = sliderPosition,
onValueChange = { sliderPosition = it })
Text(text = sliderPosition.toString())
}
Upvotes: 2
Views: 4576
Reputation: 148
Convert to rounded int and then to float
Slider(
value = sliderPosition,
onValueChange = { sliderPosition = it.roundToInt().toFloat() },
valueRange = 0f..100f
)
Upvotes: 8
Reputation: 67393
Slider has a valueRange
paremeter which is valueRange: ClosedFloatingPointRange<Float> = 0f..1f
by default, you can change it as
valueRange = 0f..100f
or valueRange = 0f..360f
or any closed range of your choosing
Slider(
value = sliderPosition,
onValueChange = { sliderPosition = it},
valueRange = 0f..100f
)
Upvotes: 1