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
🌐
CodePen
codepen.io › dylanbox › pen › MWjxrR
Double Input Form
<html> <body> <section> <h1>My cool form</h1> <form action=""> <label for="first-name">Name</label> <div class="double-input"> <input type="text" id="first-name" placeholder="First" /> <input type="text" id="last-name" placeholder="Last"/> </div> <button class="btn">Submit</button> </form> </section> </body> </html> !
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.

Discussions

Double format problems when using <input type="number">
Description I recognized that the NumberConverter can't handle decimals from a number input field properly when using a non-english (or better: not-dot separated) locale. Because the browser on... More on github.com
🌐 github.com
26
November 28, 2019
How to convert int to double using jquery or javascript when user enter input value - Stack Overflow
How to convert int to double using jquery or javascript when user enter input value? Here when user enter the input it automatically convert into double values. More on stackoverflow.com
🌐 stackoverflow.com
javascript - Validate for double type in textbox - Stack Overflow
What is the best way to checking if a valid double type number "##.##" is entered in a text box? so if there is a decimal entered once, don't let users enter it again. Would regular expressions be... More on stackoverflow.com
🌐 stackoverflow.com
November 1, 2012
html - javascript enable input on double click - Stack Overflow
I have a form with some inputs disabled. I want these inputs to be enabled when double clicked. Unfortunately, JS events seem not to fire on disabled inputs. More on stackoverflow.com
🌐 stackoverflow.com
🌐
MaxInterview
maxinterview.com › code › html-double-input-623C504FF8BC60E
MaxInterview - html double input
April 5, 2022 - ml input fix 2 decimal placestype ... form htmlhtml decimal inputheml input float numberhtml type decimalhtml number input not allow decimalfloat input 5btype 3dnumber 5d floathtml double input same input fieldform input type number decimalhtml input float labelinput type number javascript validation ...
🌐
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.
🌐
GitHub
github.com › eclipse-ee4j › krazo › issues › 118
Double format problems when using <input type="number"> · Issue #118 · eclipse-ee4j/krazo
November 28, 2019 - Description I recognized that the NumberConverter can't handle decimals from a number input field properly when using a non-english (or better: not-dot separated) locale. Because the browser only sends dot-separated values to the server,...
Author: eclipse-ee4j
🌐
Coderanch
coderanch.com › t › 113688 › languages › input-double-quotes-input-field
input double quotes in input field (HTML Pages with CSS and JavaScript forum at Coderanch)
May 9, 2003 - How to input a string surrended by double quotes in web page. it seems that all the string incluing leading double quotes will be truncated. Thanks, Lily ... If your looking to pass values with double quotes , posting the form must achieve it. If you are looking for an escape sequence, the there is an escape() method in javascript i think which will achieve that
Find elsewhere
🌐
W3C
w3c.github.io › html-reference › input.number.html
input type=number – number input control (NEW) - HTML5
The input element with a type attribute whose value is "number" represents a precise control for setting the element’s value to a string representing a number.
🌐
W3Schools
w3schools.com › tags › att_input_type_number.asp
HTML input type="number"
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
Enonic
developer.enonic.com › docs › xp › stable › cms › schemas › input-types › double
Double input type - Enonic Developer Portal
November 21, 2023 - <input name="mydouble" type="Double"> <label>My Double</label> <default>3.89</default> (1) </input> <input name="angle" type="Double"> <label>Angle (rad)</label> <config> <min>0</min> (2) <max>3.14159</max> (3) </config> </input>
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › HTML › Element › input › number
<input type="number"> HTML attribute value - HTML | MDN
It is not as semantically useful as other ways to explain your form, and can cause unexpected technical issues with your content. See <input> labels for more information. A Boolean attribute which, if present, means this field cannot be edited by the user. Its value can, however, still be changed by JavaScript code directly setting the HTMLInputElement value property.
🌐
W3Schools
w3schools.com › tags › att_input_multiple.asp
HTML input multiple Attribute
Note: The multiple attribute works with the following input types: email, and file.
🌐
W3Schools
w3schools.com › html › html_form_input_types.asp
HTML Input Types
This is how the HTML code above will be displayed in a browser: I have a bike I have a car I have a boat ... The <input type="color"> is used for input fields that should contain a color.
🌐
w3collective
w3collective.com › category: tutorial › code a double range price slider using html, css & javascript
Code a double range price slider using HTML, CSS & JavaScript - w3collective
June 28, 2024 - rangePrice.forEach((input) => { input.addEventListener("input", (e) => { let minPrice = rangePrice[0].value; let maxPrice = rangePrice[1].value; if (maxPrice - minPrice >= rangeMin && maxPrice <= rangeInput[1].max) { if (e.target.className === "min") { rangeInput[0].value = minPrice; range.style.left = (minPrice / rangeInput[0].max) * 100 + "%"; } else { rangeInput[1].value = maxPrice; range.style.right = 100 - (maxPrice / rangeInput[1].max) * 100 + "%"; } } }); });Code language: JavaScript (javascript) This function checks that the values entered fall within the minimum and maximum allowed va
🌐
W3Schools
w3schools.com › tags › att_input_type.asp
HTML input type Attribute
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.