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

302
Visualizações
JavaScript increment of the the last decimal number

I'm trying to to increment the last decimal of a number from 1.234 to 1.235

var numb = 1.234;
numb.replace(/\d$/, numb + 1);

or let just say that the problem is like following

var oNumber = 1.34567 
var oDecimalCount = 5 

increaseNumber(oNumber, oDecimalCount){ 
oNumber += //increase the 5th(oDecimalCount) decimal place 
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could do this :

  • count the numbers after the decimal point
  • use this number to remove the decimal point * 10^n
  • add 1
  • use the number to place the decimals back in place / 10^n

//I found this function here : https://www.tutorialspoint.com/decimal-count-of-a-number-in-javascript
const decimalCount = num => {
   // Convert to String
   const numStr = String(num);
   // String Contains Decimal
   if (numStr.includes('.')) {
      return numStr.split('.')[1].length;
   };
   // String Does Not Contain Decimal
   return 0;
}

let numb = 1.234;
let count = decimalCount(numb);

console.log(((numb * 10 ** count) + 1) / 10 ** count);

about 4 years ago · Juan Pablo Isaza Relatório

0

Im not sure I understand the question completely, but can't you just do it like this

let numb = 1.234;
numb += 0.001;
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