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
3 changes: 3 additions & 0 deletions src/tax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function salesTax(amountCents, ratePercent) {
return Math.round((amountCents * ratePercent) / 100);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Important

Math.round((amountCents * ratePercent) / 100)

Math.round breaks ties toward +Infinity, so a negative half-cent tax rounds toward zero: salesTax(-1, 50) returns -0 and salesTax(-3, 50) returns -1, while the positive case salesTax(1, 50) returns 1. This only matters if negative amounts (refunds or reversals) are passed in; if the order summary will handle them, pick an explicit half-away-from-zero rule and apply it to the sign separately.

🤖 Prompt for AI agents
Pull request mergestorm/sample-app#3: https://github.com/mergestorm/sample-app/pull/3 (head branch `tax`)

Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.

In `@src/tax.js` (line 2, Important):
Math.round breaks ties toward +Infinity, so a negative half-cent tax rounds toward zero: salesTax(-1, 50) returns -0 and salesTax(-3, 50) returns -1, while the positive case salesTax(1, 50) returns 1. This only matters if negative amounts (refunds or reversals) are passed in; if the order summary will handle them, pick an explicit half-away-from-zero rule and apply it to the sign separately.

}
7 changes: 7 additions & 0 deletions src/tax.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { salesTax } from "./tax.js";

test("salesTax rounds to the nearest cent", () => {
assert.equal(salesTax(1999, 8.25), 165);
});
Loading