willCosgrove
willCosgrove

Reputation: 95

HTML5 number input step bug

I am trying to use the new HTML5 number input for users to input a price. I want the step to be "0.01". This should be fairly simple, and my code looks like this:

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

Well if you click on the arrows a bit, you'll get numbers like 1.1400000000000001 or numbers like 1.1 which both don't make sense for dollars.

Does anyone know of a way to make the number field actually step by 0.01, and to have a consistent number of significant figures? Or if anyone has a more elegant solution for allowing users to input prices, I would love to hear it.

Thanks

Upvotes: 4

Views: 1949

Answers (2)

Orlando
Orlando

Reputation: 9712

this is the expected javascript behavior, you can take a look at this answer

Upvotes: 0

Shiv Kumar
Shiv Kumar

Reputation: 9799

Well, first of all expecting Html 5 stuff to work as expected so early in the game and designing applications around that is probably not such a good idea.

As for a solution, yes just to JavaScript to increment and provide the user to up/down arrows or whatever and the click event could simple increment/decrement the value by the step value you desire.

Upvotes: 2

Related Questions