在 React Native 中浮动到 Int
Float to Int in React Native
我对 React Native 还是个新手。我希望你们能帮助我。我想在滑块中将 float 更改为 int。 (在 onValueChange 中)
这是我的代码:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) => this.setState({sliderState:value})}
/>
</Block>
<Block xsSize='1/2' smSize='1/2' style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>{this.state.sliderState}%</Text>
</Block>
</Section>
我想将 <Text style={{color:'white'}}>{this.state.sliderState}%</Text>
中的输出更改为 int。现在,输出仍然是浮动的。
如果您希望值以特定方式显示,请确保在设置状态时进行更改。
这样,您就可以按照自己的方式设置值的格式。
试试这个:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) =>this.setState({sliderState:Math.round(value)})}
/>
</Block>
<Block
xsSize='1/2'
smSize='1/2'
style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>
{this.state.sliderState}%
</Text>
</Block>
</Section>
我对 React Native 还是个新手。我希望你们能帮助我。我想在滑块中将 float 更改为 int。 (在 onValueChange 中)
这是我的代码:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) => this.setState({sliderState:value})}
/>
</Block>
<Block xsSize='1/2' smSize='1/2' style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>{this.state.sliderState}%</Text>
</Block>
</Section>
我想将 <Text style={{color:'white'}}>{this.state.sliderState}%</Text>
中的输出更改为 int。现在,输出仍然是浮动的。
如果您希望值以特定方式显示,请确保在设置状态时进行更改。
这样,您就可以按照自己的方式设置值的格式。
试试这个:
<Section style={{padding:10, backgroundColor:'white', borderRadius:10, marginTop:30}}>
<Block xsSize='1/2' smSize='1/2'>
<Slider
style={{width: 200, height: 40}}
minimumValue={1}
maximumValue={100}
minimumTrackTintColor="#0197ca"
maximumTrackTintColor="#a2a2a2"
onValueChange={(value) =>this.setState({sliderState:Math.round(value)})}
/>
</Block>
<Block
xsSize='1/2'
smSize='1/2'
style={{padding:10, borderRadius:5, backgroundColor:'#0197ca', width:60, position:'relative', left:90}}>
<Text style={{color:'white'}}>
{this.state.sliderState}%
</Text>
</Block>
</Section>