소수점이하 2자리 추가
This commit is contained in:
parent
101e086a84
commit
43f70f9f79
@ -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)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// 커서를 텍스트 끝으로 이동하고 스크롤 처리
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user