diff --git a/src/utils/totalCost.ts b/src/utils/totalCost.ts index 7c8c592..01423a4 100644 --- a/src/utils/totalCost.ts +++ b/src/utils/totalCost.ts @@ -1,6 +1,9 @@ import { STORAGE_NAME_TOTALCOST } from "@/const"; export function addTotalCost(cost: number) { + if (isNaN(cost)) { + return; + } let totalCost = getTotalCost(); totalCost += cost; localStorage.setItem(STORAGE_NAME_TOTALCOST, `${totalCost}`); @@ -10,6 +13,9 @@ export function getTotalCost(): number { let totalCost = parseFloat( localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0", ); + if (isNaN(totalCost)) { + totalCost = 0; + } return totalCost; }