Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Number Input - Step Attribute - format value to 2 decimal places

I am creating a currency input and I want my counter to be able to go up in pence, however, I currently have an issue:

at the moment when I click the step, I get something like 0.38, 0.39, 0.4, 0.41, 0.42

I would want the "0.4" to actually be 0.40, but im unsure how i manage this, would anyone be able to help?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

<input type="number" step="0.10" value="10"></input>

You can use HTML5's step attribute to increment by the particular decimal.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Listen for the input event and format the input's value accordingly.

document.getElementById('myInput').addEventListener('input', ({target}) => {
    target.value = Number(target.value).toFixed(2);
});
<input id="myInput" type="number" step="0.01" value="0.00" />

The toFixed method was made for this, but it's only available on numbers. We infer a number from the current (string) value with Number() then format it to 2 decimal places using toFixed

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda