From 2cdf9b3e3d51dd9a2ef06d1019135dad6408db70 Mon Sep 17 00:00:00 2001 From: Yeonseo-Jo Date: Fri, 27 Oct 2023 04:04:28 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=ED=99=94=ED=8F=90=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=ED=91=9C=EC=8B=9C(localString)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- week2/assign2/script.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/week2/assign2/script.js b/week2/assign2/script.js index da2b39c..3dd1896 100644 --- a/week2/assign2/script.js +++ b/week2/assign2/script.js @@ -21,7 +21,7 @@ const renderHistory = () => { historyBox.innerHTML = ` ${category} ${contents} - ${amount} + ${amount.toLocaleString()} `; historyContainer.appendChild(historyBox); @@ -31,10 +31,10 @@ const renderHistory = () => { // 총 자산, 수입, 지출 렌더링 함수 const renderTotalBalance = () => { const incomeAmounts = [...$$(".history-amount.income")].map((history) => { - return Number(history.innerHTML); + return Number(history.innerHTML.replaceAll(",", "")); }); const expenseAmounts = [...$$(".history-amount.expense")].map((history) => { - return Number(history.innerHTML); + return Number(history.innerHTML.replaceAll(",", "")); }); SUM_INCOME = incomeAmounts.reduce((sum, curr) => { @@ -46,13 +46,17 @@ const renderTotalBalance = () => { }, 0); const totalAmount = $(".asset__box__total-amount"); - totalAmount.innerHTML = INIT_BALANCE + SUM_INCOME - SUM_EXPENSE; + totalAmount.innerHTML = ( + INIT_BALANCE + + SUM_INCOME - + SUM_EXPENSE + ).toLocaleString(); const totalExpense = $(".detail-amount__num__minus"); - totalExpense.innerHTML = SUM_EXPENSE; + totalExpense.innerHTML = SUM_EXPENSE.toLocaleString(); const totalIncome = $(".detail-amount__num__plus"); - totalIncome.innerHTML = SUM_INCOME; + totalIncome.innerHTML = SUM_INCOME.toLocaleString(); }; // 초기 데이터 렌더링 함수 @@ -154,7 +158,9 @@ const checkNumber = (event) => { if (isNaN(event.key)) { alert("숫자만 입력하세요"); } - event.target.value = event.target.value.replace(/[^0-9]/g, ""); + event.target.value = Number( + event.target.value.replace(/[^0-9]/g, "") + ).toLocaleString(); }; // 금액에 숫자만 입력하도록 하는 핸들러 함수 @@ -181,7 +187,7 @@ const addNewList = () => { historyBox.innerHTML = ` ${newCategory} ${newContents} - ${newAmount} + ${newAmount.toLocaleString()} `; if (newCategory && newAmount && newContents) {