The number type has a step value controlling which numbers are valid (along with max and min), which defaults to 1. This value is also used by implementations for the stepper buttons (i.e. pressing up increases by step).

Simply change this value to whatever is appropriate. For money, two decimal places are probably expected:

<label for="totalAmt">Total Amount</label>
<input type="number" step="0.01" id="totalAmt">

(I'd also set min=0 if it can only be positive)

If you'd prefer to allow any number of decimal places, you can use step="any" (though for currencies, I'd recommend sticking to 0.01). In Chrome & Firefox, the stepper buttons will increment / decrement by 1 when using any. (thanks to Michal Stefanow's answer for pointing out any, and see the relevant spec here)

Here's a playground showing how various steps affect various input types:

<form>
  <input type=number step=1 /> Step 1 (default)<br />
  <input type=number step=0.01 /> Step 0.01<br />
  <input type=number step=any /> Step any<br />
  <input type=range step=20 /> Step 20<br />
  <input type=datetime-local step=60 /> Step 60 (default)<br />
  <input type=datetime-local step=1 /> Step 1<br />
  <input type=datetime-local step=any /> Step any<br />
  <input type=datetime-local step=0.001 /> Step 0.001<br />
  <input type=datetime-local step=3600 /> Step 3600 (1 hour)<br />
  <input type=datetime-local step=86400 /> Step 86400 (1 day)<br />
  <input type=datetime-local step=70 /> Step 70 (1 min, 10 sec)<br />
</form>
Run code snippetEdit code snippet Hide Results Copy to answer Expand


As usual, I'll add a quick note: remember that client-side validation is just a convenience to the user. You must also validate on the server-side!

Answer from Dave on Stack Overflow
Top answer
1 of 13
2477

The number type has a step value controlling which numbers are valid (along with max and min), which defaults to 1. This value is also used by implementations for the stepper buttons (i.e. pressing up increases by step).

Simply change this value to whatever is appropriate. For money, two decimal places are probably expected:

<label for="totalAmt">Total Amount</label>
<input type="number" step="0.01" id="totalAmt">

(I'd also set min=0 if it can only be positive)

If you'd prefer to allow any number of decimal places, you can use step="any" (though for currencies, I'd recommend sticking to 0.01). In Chrome & Firefox, the stepper buttons will increment / decrement by 1 when using any. (thanks to Michal Stefanow's answer for pointing out any, and see the relevant spec here)

Here's a playground showing how various steps affect various input types:

<form>
  <input type=number step=1 /> Step 1 (default)<br />
  <input type=number step=0.01 /> Step 0.01<br />
  <input type=number step=any /> Step any<br />
  <input type=range step=20 /> Step 20<br />
  <input type=datetime-local step=60 /> Step 60 (default)<br />
  <input type=datetime-local step=1 /> Step 1<br />
  <input type=datetime-local step=any /> Step any<br />
  <input type=datetime-local step=0.001 /> Step 0.001<br />
  <input type=datetime-local step=3600 /> Step 3600 (1 hour)<br />
  <input type=datetime-local step=86400 /> Step 86400 (1 day)<br />
  <input type=datetime-local step=70 /> Step 70 (1 min, 10 sec)<br />
</form>
Run code snippetEdit code snippet Hide Results Copy to answer Expand


As usual, I'll add a quick note: remember that client-side validation is just a convenience to the user. You must also validate on the server-side!

2 of 13
219

Via: http://blog.isotoma.com/2012/03/html5-input-typenumber-and-decimalsfloats-in-chrome/

But what if you want all the numbers to be valid, integers and decimals alike? In this case, set step to “any”

<input type="number" step="any" />

Works for me in Chrome, not tested in other browsers.

🌐
GeeksforGeeks
geeksforgeeks.org › html › how-to-set-float-input-type-in-html5
How to set float input type in HTML5 ? - GeeksforGeeks
July 23, 2025 - The input type is set to "number" to indicate that it accepts numeric values. The min attribute specifies the minimum value that can be entered, which is 0 in this case. The max attribute specifies the maximum value that can be entered, which ...
Discussions

How to make python accept both int and float input???
i need my calculator to accept both the inputs in form of integer and floating point number Neeeeed Hellp ASAP More on sololearn.com
🌐 sololearn.com
161
66
How would I make a program only accept floats and integers?
The basic steps you need are: Ask for input Check if the input is a float If not a float, show an error message and return to step 1 Happy to help more with any of these specific steps, but try to figure them out yourself first (by googling). More on reddit.com
🌐 r/learnpython
10
8
October 21, 2022
Take Float input with number_input
Hello, I am trying to take float as input with the help of number_input but it’s converting it into integer value somehow. totChol = st.number_input(label=“cholesterol level in mg/dL”,step=1,format=“%i”) st.write(totChol) sysBP = st.number_input(label=“systolic blood pressure”... More on discuss.streamlit.io
🌐 discuss.streamlit.io
2
0
June 26, 2021
Float input is apparently wrong
The directions explicitly tell you not to use a prompt with input(). You used a prompt with input(). More on reddit.com
🌐 r/learnpython
6
3
February 2, 2022
🌐
IncludeHelp
includehelp.com › python › read-input-as-a-float.aspx
Read input as a float in Python
April 20, 2025 - Thus, we use input() function to read input and convert it into a float using float() function.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-input-float
How to take Float user input in Python | bobbyhadz
April 9, 2024 - We used a while loop to only allow the user to enter a float value. The code snippet keeps prompting the user for input until they enter a valid float.
Find elsewhere
🌐
TradingCode
tradingcode.net › tradingview › float-number-input
Code float number input in Pine Script • TradingCode
January 26, 2022 - Float inputs are a common way to configure an indicator or strategy. They can, for instance, set the multiplier of some value, like the Average True Range (ATR). Or define a percentage offset, like we’d use with a stop-loss or profit target.
🌐
Panel
panel.holoviz.org › reference › widgets › FloatInput.html
FloatInput — Panel v1.9.3
float_input = pn.widgets.FloatInput(label='FloatInput', value=5., step=1e-1, start=0, end=1000) float_input
🌐
TutorialsPoint
tutorialspoint.com › how-to-set-float-input-type-in-html5
How to set float input type in HTML5?
While HTML5 lacks a dedicated float input type, the inputmode="decimal" approach offers excellent mobile usability, while the step attribute with type="number" provides precise decimal control and validation.
🌐
Sololearn
sololearn.com › en › Discuss › 2073531 › -input-float-
float(input("Enter a number
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Davrot
davrot.github.io › pytutorial › python_basics › input_output_string_int_float
input, print, string, int, float
Return a floating point number constructed from a number or string x. If the argument is a string, it should contain a decimal number, optionally preceded by a sign, and optionally embedded in whitespace. The optional sign may be ‘+’ or ‘-‘; a ‘+’ sign has no effect on the value ...
🌐
Codemia
codemia.io › home › knowledge hub › is there a float input type in html5?
Is there a float input type in HTML5? | Codemia
January 2, 2025 - In conclusion, while HTML5 does not feature a specialized 'float' input type, the number input type, when configured properly, suffices for most practical needs involving floating-point inputs in web forms. To enforce precision and handle more complex scenarios, developers should complement it with additional client-side JavaScript.
🌐
GeeksforGeeks
geeksforgeeks.org › python › float-in-python
float() in Python - GeeksforGeeks
September 18, 2025 - In Python, the float() function is used to convert numbers or numeric strings into floating-point numbers. A floating-point number is simply a number with a decimal point (for example, 3.14, -0.5, or 10.0). This function is especially useful ...
🌐
LabEx
labex.io › tutorials › python-how-to-convert-inputs-to-float-safely-421320
How to convert inputs to float safely | LabEx
Float conversion is the process of transforming input data into floating-point numbers in Python.
🌐
Quora
quora.com › How-do-I-take-an-input-type-float-number-in-HTML
How to take an input type float number in HTML - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Streamlit
discuss.streamlit.io › using streamlit
Take Float input with number_input - Using Streamlit - Streamlit
June 26, 2021 - Hello, I am trying to take float as input with the help of number_input but it’s converting it into integer value somehow. totChol = st.number_input(label=“cholesterol level in mg/dL”,step=1,format=“%i”) st.write(totChol) sysBP = st.number_input(label=“systolic blood pressure”...
🌐
Reddit
reddit.com › r/learnpython › float input is apparently wrong
r/learnpython on Reddit: Float input is apparently wrong
February 2, 2022 -

Hi, I've posted here recently and I'm sure I will again. The site myself course is on seems ridiculously made, and makes me question existence.

Part of a question reads "Read a float from the keyboard and assign it to a variable named d. (Do not print a prompt. Use the input() function without a prompt string to read the input)

My interpretation was to type d = float(input('Type a float ')) 87.5

It's a site called Pearson Revel if anyone else took a similar class, btw. Anyway, it says my program is wrong because "Correct solutions that use float tend to also use ___". The statement ends with nothing and doesn't say what's wrong. Any help would be greatly appreciated, and thanks in advance!

EDIT - I tried to use no prompt and it still marked it wrong. Actually, it marked more flaws in the program w/o a prompt.

🌐
Reddit
reddit.com › r/learnpython › how to accept only integer or float inputs?
r/learnpython on Reddit: How to accept only integer or float inputs?
February 23, 2016 -

My current code accepts integers that are greater than 0, which is what I want, but I also want to accept floats/decimals as well. How would I do this? Here is my current code:

while True:
            try:
                time = int(input("How much time has elapsed since your last stop (in hours)?"))
            except ValueError:
                print("Enter a valid number of hours!")
                continue
            if time > 0:
                givenTime[2] = time
                break

Indentation is off here for some reason, but believe me when I say that the indentation in the actual code is correct..

Can I just do time = int or float(input("How much time has elapsed since your last stop (in hours)?")) or would this be wrong? Any help would be appreciated.

edit: nope,

time = int or float(input("How much time has elapsed since your last stop (in hours)?"))

doesn't work.