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

144
Visualizações
Rounding depending on the multiplicity

The user enters 110 into the quantity, but since there are 20 pieces in the multiplicity, the quantity should automatically be recalculated upwards, it should be 120 pieces.

If, for example, the multiplicity is 100, and the client needs 1010 pieces, and he drives 1010 pieces into the quantity field, it should be recalculated to 1100 pieces.

I need rounding up depending on the multiplicity of goods.

curValue = Math.floor(Math.ceil((curValue * this.precisionFactor )/this.precisionFactor))

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

0

The simplest way, I think, to achieve this, is to first see how many 'batches' of size multiplicity there are, rounding this up to the nearest integer, and then multiplying this by the multiplicity again. That is

function multRound(amount, batchSize) {
  // round up to whole number of batches
  let numBatches = Math.ceil(amount/batchSize);
  
  // return the number times the size of each
  let total = numBatches * batchSize;
  return total;
}

Of course you can quite easily make this a one-liner, but I thought it'd be clearer to write it like this.

about 4 years ago · Juan Pablo Isaza Relatório

0

var curValue = 105;
var multiplicity = 20;

var amountToAdd = 0;
for (var i = curValue; i >= multiplicity; i = i - multiplicity ) {
    var temp = i - multiplicity;
  amountToAdd = multiplicity - temp;
}

console.log("new value: " + (curValue + amountToAdd))

about 4 years ago · Juan Pablo Isaza Relatório

0

You can divide the value by multiplicity, and get the integer part using Math.floor() and add 1 to it (since you want it to be rounded up). Then return this value multiplied by multiplicity.

function round(currValue, multi){
  return multi*(Math.floor(currValue/multi) + 1);
}

console.log(round(105, 20));
console.log(round(1010, 100));

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