1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

(bug) use Math.round instant of Math.trunc for fix float multify (ex: 37.8*100)

This commit is contained in:
Du Peng 2022-10-04 17:26:39 +02:00
parent a9dc7b4dd7
commit 9066148572
2 changed files with 6 additions and 6 deletions

View File

@ -5,9 +5,9 @@ export const computePriceWithCoupon = (price: number, coupon?: Coupon): number =
return price;
}
if (coupon.type === 'percent_off') {
return (Math.trunc(price * 100) - (Math.trunc(price * 100) * coupon.percent_off / 100)) / 100;
return (Math.round(price * 100) - (Math.round(price * 100) * coupon.percent_off / 100)) / 100;
} else if (coupon.type === 'amount_off' && price > coupon.amount_off) {
return (Math.trunc(price * 100) - Math.trunc(coupon.amount_off * 100)) / 100;
return (Math.round(price * 100) - Math.round(coupon.amount_off * 100)) / 100;
}
return price;
};

View File

@ -6,7 +6,7 @@ export default class OrderLib {
* Get the order item total
*/
static itemAmount = (item): number => {
return item.quantity * Math.trunc(item.amount * 100) / 100;
return item.quantity * Math.round(item.amount * 100) / 100;
};
/**
@ -23,7 +23,7 @@ export default class OrderLib {
static offeredAmount = (order: Order): number => {
return order.order_items_attributes
.filter(i => i.is_offered)
.map(i => Math.trunc(i.amount * 100) * i.quantity)
.map(i => Math.round(i.amount * 100) * i.quantity)
.reduce((acc, curr) => acc + curr, 0) / 100;
};
@ -31,14 +31,14 @@ export default class OrderLib {
* Get the total amount before offered amount
*/
static totalBeforeOfferedAmount = (order: Order): number => {
return (Math.trunc(order.total * 100) + Math.trunc(this.offeredAmount(order) * 100)) / 100;
return (Math.round(order.total * 100) + Math.round(this.offeredAmount(order) * 100)) / 100;
};
/**
* Get the coupon amount
*/
static couponAmount = (order: Order): number => {
return (Math.trunc(order.total * 100) - Math.trunc(computePriceWithCoupon(order.total, order.coupon) * 100)) / 100.00;
return (Math.round(order.total * 100) - Math.round(computePriceWithCoupon(order.total, order.coupon) * 100)) / 100.00;
};
/**