I need a simple input box to be a floating point number (anything with a .
really). As it is right now, it doesn't allow me to put the dot and do a floating point. Should be simple but I can't find much on this.
Here is roughly the current code:
class MyComponent extends React.Component {
render () {
return (
<td>
<label> Value: </label>
<input
type='number'
min='0'
max='20'
className='form-control'
value={this.state.value}
onChange= {(evt) => this.onValueChange('value', evt.target.value)}
/>
</td>
)
}
}
The number type has a step
value controlling which numbers precision which defaults to 1
.
You can use this to set the floating point precision
<input type="number" step="0.1">
You will have
class MyComponent extends React.Component {
render () {
return (
<td>
<label> Value: </label>
<input
type='number'
step="0.1"
min='0'
max='20'
className='form-control'
value={this.state.value}
onChange= {(evt) => this.onValueChange('value', evt.target.value)}
/>
</td>
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With