Handle NaN values in total cost calculations
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import { STORAGE_NAME_TOTALCOST } from "@/const";
|
import { STORAGE_NAME_TOTALCOST } from "@/const";
|
||||||
|
|
||||||
export function addTotalCost(cost: number) {
|
export function addTotalCost(cost: number) {
|
||||||
|
if (isNaN(cost)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let totalCost = getTotalCost();
|
let totalCost = getTotalCost();
|
||||||
totalCost += cost;
|
totalCost += cost;
|
||||||
localStorage.setItem(STORAGE_NAME_TOTALCOST, `${totalCost}`);
|
localStorage.setItem(STORAGE_NAME_TOTALCOST, `${totalCost}`);
|
||||||
@@ -10,6 +13,9 @@ export function getTotalCost(): number {
|
|||||||
let totalCost = parseFloat(
|
let totalCost = parseFloat(
|
||||||
localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0",
|
localStorage.getItem(STORAGE_NAME_TOTALCOST) ?? "0",
|
||||||
);
|
);
|
||||||
|
if (isNaN(totalCost)) {
|
||||||
|
totalCost = 0;
|
||||||
|
}
|
||||||
return totalCost;
|
return totalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user