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

129
Visualizações
How to generate the sequence between 0.1 to 46.61 with interval 0.1

Hi i want to generate every possible interval from 0.1 to 46.61

my expected result must look like this

0.1 0.2 0.3 ... ... 46.1 46.2 46.3 46.4 46.5 46.6

Here is what i have tried but not working correctly

let wholeDuration = 46.61;

let interval = 0.1, res = [];

for(let i = 0; i < wholeDuration; i++){
   res.push(interval * i)
}

console.log(res);

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Too bad, this is how machine floating precision operations work. However, there are some workarounds that can produce result closer to "familiar". One of thos is to use integer as counter and divide by 10 (this works in your case because 1 is excatly 10 times your interval value)

let wholeDuration = 46.61, interval = 0.1, res = [];
let divisor = 10;
let limit = 466.1; // wholeDuration * divisor;
let step = 1; // interval * divisor

for(let i = 0; i < limit; i += step){
   res.push(i / divisor);
}

console.log(res);

about 4 years ago · Juan Pablo Isaza Relatório

0

When you know the length of your future array is better to use new Array instead of loops.

See my example below:

let pointFrom = 0.1;
let pointTo = 46.6;
let multiplier = 0.1;

let arr = new Array(((pointTo - pointFrom) / 0.1) + 1).fill(null).map((_, x) => parseFloat(((x * multiplier) + pointFrom).toFixed(1)));
console.log(arr, arr.length)

about 4 years ago · Juan Pablo Isaza Relatório

0

Normally JavaScript knows just floating point arithmetic. But some JavaScript engines have optimizations for integer arithmetic. So just use integers for the incrementation.

let res = [];

for (let i = 1; i < 467; i++) {
   res.push (i/10)
}

console.log (res);

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