From 655b8f29cddd89673a9a2954341a5e8a29606f5f Mon Sep 17 00:00:00 2001 From: basssy Date: Sat, 7 Dec 2024 07:01:24 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=AC=EC=A0=81=EC=84=9C=20pkgAsp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/estimate/Estimate.jsx | 32 ++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 63c35b35..c800d831 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -493,19 +493,37 @@ export default function Estimate({ params }) { setSelection(newSelection) } + function formatNumberWithComma(number) { + return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + } + //주택PKG input 변경 const onChangePkgAsp = (value) => { if (estimateContextState.estimateType === 'YJSS') { - let pkgAsp = Number(value.replace(/[^-\.0-9]/g, '').replaceAll(',', '')) - if (isNaN(pkgAsp)) { - pkgAsp = 0 - } else { - pkgAsp = pkgAsp.toLocaleString() + let newValue = value.replace(/[^0-9.]/g, '') + if (newValue.length > 1) { + newValue = newValue.replace(/(^0+)/, '') + if (newValue.length === 0) { + newValue = '0' + } } - //현재 PKG용량값 가져오기 + const parts = newValue.split('.') + if (parts.length > 2) { + newValue = parts[0] + '.' + parts.slice(1).join('') + } + + if (parts[1] && parts[1].length > 2) { + newValue = parts[0] + '.' + parts[1].substring(0, 2) + } + + let pkgAsp = newValue || '0' + + //현재 PKG용량값 가져오기 let totVolKw = estimateContextState.totVolKw * 1000 - let pkgTotPrice = pkgAsp?.replaceAll(',', '') * totVolKw * 1000 + let pkgTotPrice = parseFloat(pkgAsp?.replaceAll(',', '')) * totVolKw * 1000 + + // pkgAsp = formatNumberWithComma(parseFloat(pkgAsp).toFixed(2)) setEstimateContextState({ pkgAsp: pkgAsp,