Wanna React 로고 이미지

menu-opener icon
  • 홈
  • 태그
  • 방명록
  • Team Github 바로가기
<input type="number" />에서 leading zero 제거하기 포스팅 썸네일 이미지

원두마켓

<input type="number" />에서 leading zero 제거하기

문제 에 키보드로 숫자를 입력하면 입력값 앞에 0이 남아있는 문제가 발생했다. 문제 코드 const [totalCount, setTotalCount] = useState(1); const changeCount = (e: ChangeEvent) => { const count = +e.currentTarget.value; if (count > 100) { return; } setTotalCount(count); }; return ( )원인 분석 & 시행착오 input의 속성 value의 자료형은 문자열이므로 "033"이 그대로 totalCount에 할당되는 게 원인일 거라 생각했다. 하지만 setTotalCount에 "033"를 넘겨줄 때 +연산자를 이용해 숫자 33으로 형변환해서 넣어주므로 앞자리에 0이 ..

2022.03.25 게시됨

1

공지사항

최근글

인기글

최근 작성된 댓글

태그 클라우드

  • 에러처리
  • MongoDB
  • input
  • next.js
  • 제거
  • 입력
  • 없애기
  • husky
  • mongoose
  • git hooks
  • Number
  • 0
  • 앞
  • 에러핸들링
Copyright . 베이스캠프 all rights reserved.
Designed by 베이스캠프
닫기 아이콘
사이드 프로필 배경이미지
블로그 이미지

Lahee

  • 분류 전체보기 (7)
    • 팀 소개 (1)
    • 원두마켓 (6)
    • 랜덤 interview (0)

전체

오늘

어제

Designed by 베이스캠프

티스토리툴바