[1252] 일본의 전각 숫자, 반각 함수변경 #298
@ -22,7 +22,7 @@ import { stuffSearchState } from '@/store/stuffAtom'
|
||||
import { QcastContext } from '@/app/QcastProvider'
|
||||
import { useCanvasMenu } from '@/hooks/common/useCanvasMenu'
|
||||
import { useSwal } from '@/hooks/useSwal'
|
||||
import { sanitizeDecimalInputEvent} from '@/util/input-utils'
|
||||
import { sanitizeIntegerInputEvent } from '@/util/input-utils'
|
||||
|
||||
export default function StuffDetail() {
|
||||
const [stuffSearch, setStuffSearch] = useRecoilState(stuffSearchState)
|
||||
|
||||
@ -24,15 +24,38 @@ export const onlyNumberWithDotInputChange = (e, callback) => {
|
||||
// Number normalization utilities
|
||||
// =============================
|
||||
// 1) Normalize any string to NFKC and keep only ASCII digits 0-9.
|
||||
// 1) Normalize any string to keep only ASCII digits 0-9
|
||||
export function normalizeDigits(value) {
|
||||
return String(value ?? '').normalize('NFKC').replace(/[^0-9]/g, '')
|
||||
if (value == null) return '';
|
||||
|
||||
// First convert full-width numbers to half-width
|
||||
const str = String(value).replace(/[0-9]/g, s =>
|
||||
String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
|
||||
);
|
||||
|
||||
// Then remove all non-digit characters
|
||||
return str.replace(/\D/g, '');
|
||||
}
|
||||
|
||||
// 2) Normalize decimal numbers (allow one dot).
|
||||
// 2) Normalize decimal numbers (allow one dot)
|
||||
export function normalizeDecimal(value) {
|
||||
const s = String(value ?? '').normalize('NFKC').replace(/[^0-9.]/g, '')
|
||||
const [head, ...rest] = s.split('.')
|
||||
return rest.length ? `${head}.${rest.join('').replace(/\./g, '')}` : head
|
||||
if (value == null) return '';
|
||||
|
||||
// Convert full-width numbers and dot to half-width
|
||||
let str = String(value).replace(/[0-9.]/g, s =>
|
||||
s === '.' ? '.' : String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
|
||||
);
|
||||
|
||||
// Handle multiple dots by keeping only the first one
|
||||
const parts = str.split('.');
|
||||
if (parts.length > 1) {
|
||||
str = parts[0] + '.' + parts.slice(1).join('');
|
||||
}
|
||||
|
||||
// Remove any remaining non-digit and non-dot characters
|
||||
// and ensure only one dot remains
|
||||
return str.replace(/[^\d.]/g, '')
|
||||
.replace(/^(\d*\.\d*).*$/, '$1');
|
||||
}
|
||||
|
||||
// 2-1) Limit fractional digits for decimal numbers. Default to 2 digits.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user