0

I have an input field that currently takes in type=number, however this does not allow for decimal numbers, i do need to allow the user to have decimal input but i cant seem to get it working, would regex possibly be the solution to this problem as i would need some sort of validation.

<FormControl fullWidth style={{ width: '50%' }}>
    <InputLabel htmlFor="estimatedValue">Estimated Value</InputLabel>
    <Input
        type="number"
        id="estimatedValue"
        startAdornment={<InputAdornment position="start">£</InputAdornment>}
    />
</FormControl>
1

1 Answer 1

3

To achieve expected result, use step with type number for input

Please below link for reference from MDN

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Allowing_decimal_values

<input type="number" step="0.01">

Sign up to request clarification or add additional context in comments.

8 Comments

it doesn't quite seem to work for me, still errors saying by rounding the number down or up
@PaulWillo96, could you confirm the range of values which you are trying for input field, as you can set max and min values
any value, however it can be a integer or float, min would be 0 as minus would not be accepted, max could be anything
@PaulWillo96, codepen.io/nagasai/pen/XLWGyv , as mentioned in docs - You can still manually enter any number but it will be invalid and increase/decrease will not work for invalid number
are you using regex/ function on that field which seems to rounding it off
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.