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

140
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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