Skip to content

Commit

Permalink
floating bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwormhole committed Jan 1, 2024
1 parent b280f38 commit 51ca68c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"prepare": "svelte-kit sync"
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.0.6",
"bulma": "^0.9.4",
"sass": "^1.69.5",
"sass": "^1.69.6",
"svelte": "^4.2.8",
"svelte-check": "^3.6.2",
"tslib": "^2.6.2",
Expand Down
32 changes: 16 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions src/lib/InvoiceForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { browser } from "$app/environment";
import { goto } from "$app/navigation";
import { invoice } from "../store";
import { DecimalFixed } from "./decimal";
import { DecimalFixed, DecimalFixedNum } from "./decimal";
const currencies = ["£", "$", ""];
const fromPlaceholder = `From Goldenhand Software
Expand All @@ -26,12 +26,13 @@ [email protected]
for (const row of $invoice.rows) {
if (row.rate == undefined || row.quantity == undefined) {
row.amount = "";
} else {
row.rate = Math.floor(row.rate * 100) / 100;
row.quantity = Math.floor(row.quantity * 100) / 100;
row.amount = DecimalFixed(row.rate * row.quantity);
$invoice.totalAmount += parseFloat(row.amount);
}
continue
}
row.rate = DecimalFixedNum(row.rate);
row.quantity = DecimalFixedNum(row.quantity);
row.amount = DecimalFixed(row.rate * row.quantity);
$invoice.totalAmount += parseFloat(row.amount);
}
}
Expand Down Expand Up @@ -78,8 +79,8 @@ [email protected]
function setAutoDueDate(event: Event) {
const target = event.target as HTMLInputElement;
const futureDate = new Date(Date.parse(target.value) + 15 * dayInMs);
$invoice.dueDate = futureDate.toISOString().split('T')[0];
const futureDate = new Date(Date.parse(target.value) + 15 * dayInMs);
$invoice.dueDate = futureDate.toISOString().split("T")[0];
}
function addRow() {
Expand Down Expand Up @@ -269,7 +270,7 @@ [email protected]
<li class="list-group-item">
<p class="subtitle has-text-weight-bold">
Total: {$invoice.currencySymbol}{DecimalFixed(
$invoice.totalAmount
$invoice.totalAmount,
)}
</p>
</li>
Expand Down
8 changes: 7 additions & 1 deletion src/lib/decimal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function DecimalFixed(n: number): string {
return (Math.floor(n * 100) / 100).toFixed(2).toString();
return DecimalFixedNum(n).toFixed(2);
}

export function DecimalFixedNum(n: number) {
let res: number = parseFloat((n * 100).toFixed(2));
res = Math.floor(res) / 100;
return res;
}

0 comments on commit 51ca68c

Please sign in to comment.