Skip to content

Commit

Permalink
group order form: round values
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Jul 8, 2022
1 parent 0f0bc0e commit b6b6b31
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/assets/javascripts/group-order-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,22 @@ class GroupOrderForm {

const missing = this.calcMissingItems(packSize, totalQuantity, totalTolerance, minimumOrderQuantity);

used$.text(used);
unused$.text(unused);
used$.text(round(used));
unused$.text(round(unused));

usedTolerance$.text(usedTolerance);
unusedTolerance$.text(unusedTolerance);
usedTolerance$.text(round(usedTolerance));
unusedTolerance$.text(round(unusedTolerance));

totalPacks$.text(totalPacks);
totalPacks$.text(round(totalPacks));

totalPacks$.css('color', this.packCompletedFromTolerance(packSize, totalQuantity, totalTolerance) ? 'grey' : 'auto');

totalQuantity$.text(totalQuantity);
totalTolerance$.text(totalTolerance);
totalPrice$.text(I18n.l('currency', totalPrice));
totalPrice$.data('price', totalPrice);
totalQuantity$.text(round(totalQuantity));
totalTolerance$.text(round(totalTolerance));
totalPrice$.text(I18n.l('currency', round(totalPrice)));
totalPrice$.data('price', round(totalPrice));

missing$.text(missing);
missing$.text(round(missing));
if (packSize > 1 || minimumOrderQuantity > 1) {
this.setRowStyle(row$, missing, granularity);
}
Expand Down Expand Up @@ -221,6 +221,9 @@ class GroupOrderForm {


function round(num, precision) {
if (precision === undefined) {
precision = 2;
}
const factor = precision * Math.pow(10, precision);
return Math.round((num + Number.EPSILON) * factor) / factor;
}

0 comments on commit b6b6b31

Please sign in to comment.