Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions target-service/files/welcome.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello from storage
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public int calculateUnitPrice(int totalCents, int quantity) {

/**
* Calculates the discounted price for a bulk order.
* BUG: Uses double for intermediate calculation, causing floating-point precision loss.
* Uses BigDecimal throughout to avoid floating-point precision loss.
*/
public BigDecimal calculateDiscountPrice(BigDecimal total, double discountRate, int quantity) {
if (quantity <= 0) {
Expand All @@ -25,7 +25,8 @@ public BigDecimal calculateDiscountPrice(BigDecimal total, double discountRate,
if (discountRate <= 0 || discountRate >= 1) {
throw new IllegalArgumentException("discountRate must be between 0 and 1, but got: " + discountRate);
}
double perItem = total.doubleValue() * discountRate;
return BigDecimal.valueOf(perItem * quantity);
BigDecimal discountRateBD = BigDecimal.valueOf(discountRate);
BigDecimal quantityBD = BigDecimal.valueOf(quantity);
return total.multiply(discountRateBD).multiply(quantityBD);
}
}