Handle NaN values in total cost calculations
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user