Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!