Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda