From 43f70f9f79da59656f2f10b56503ffba5dfa9293 Mon Sep 17 00:00:00 2001 From: ysCha Date: Mon, 24 Nov 2025 14:03:10 +0900 Subject: [PATCH] =?UTF-8?q?=EC=86=8C=EC=88=98=EC=A0=90=EC=9D=B4=ED=95=98?= =?UTF-8?q?=202=EC=9E=90=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/common/input/CalcInput.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/common/input/CalcInput.jsx b/src/components/common/input/CalcInput.jsx index 32323560..17af010e 100644 --- a/src/components/common/input/CalcInput.jsx +++ b/src/components/common/input/CalcInput.jsx @@ -48,14 +48,23 @@ export const CalculatorInput = forwardRef( const calculator = calculatorRef.current let newDisplayValue = '' + // 소수점 이하 2자리 제한 로직 추가 + const shouldPreventInput = (value) => { + const decimalParts = (value || '').split('.') + return decimalParts.length > 1 && decimalParts[1].length >= 2 + } + if (hasOperation) { // 연산자 이후 숫자 입력 시 if (calculator.currentOperand === '0' || calculator.shouldResetDisplay) { calculator.currentOperand = num.toString() calculator.shouldResetDisplay = false - } else { + }else if (!shouldPreventInput(calculator.currentOperand)) { //소수점 이하2자리 calculator.currentOperand = (calculator.currentOperand || '') + num } + // else { + // calculator.currentOperand = (calculator.currentOperand || '') + num + // } newDisplayValue = calculator.previousOperand + calculator.operation + calculator.currentOperand setDisplayValue(newDisplayValue) } else { @@ -68,7 +77,7 @@ export const CalculatorInput = forwardRef( if (!hasOperation) { onChange(calculator.currentOperand) } - } else { + } else if (!shouldPreventInput(calculator.currentOperand)) { //소수점 이하2자리 calculator.currentOperand = (calculator.currentOperand || '') + num newDisplayValue = calculator.currentOperand setDisplayValue(newDisplayValue) @@ -76,6 +85,14 @@ export const CalculatorInput = forwardRef( onChange(newDisplayValue) } } + // else { + // calculator.currentOperand = (calculator.currentOperand || '') + num + // newDisplayValue = calculator.currentOperand + // setDisplayValue(newDisplayValue) + // if (!hasOperation) { + // onChange(newDisplayValue) + // } + // } } // 커서를 텍스트 끝으로 이동하고 스크롤 처리