Skip to content

fix: formatNumber가 8자리 숫자를 0.1억처럼 잘못 표시하는 문제 수정 - #703

Closed
SOPICKS wants to merge 1 commit into
koreanbots:masterfrom
SOPICKS:fix/format-number
Closed

SOPICKS wants to merge 1 commit into
koreanbots:masterfrom
SOPICKS:fix/format-number

Conversation

@SOPICKS

@SOPICKS SOPICKS commented Oct 24, 2026 •

Copy link
Copy Markdown

문제

formatNumber가 자릿수를 4로 나눠 단위를 고르기 때문에 몇 구간에서 틀린 값이 나옵니다.

입력 현재 기대
9,999,999 1천 1000만
10,000,000 0.1억 1000만
12,345,678 0.1억 1200만
99,999,999 1억 1억
  • 8자리(1000만~9999만)는 length / 4 = 2라서 억 단위로 가고 0.1억처럼 표시됩니다.
  • 9,999,999는 toPrecision(2) 결과가 1000이 되어 '1천' 분기에 걸립니다.

수정

  • 유효숫자 두 자리로 먼저 반올림한 뒤, 값 크기로 단위(만·억·조·경)를 고르도록 바꿨습니다.
  • 기존 테스트는 모두 그대로 통과하고, 위 구간 테스트를 추가했습니다.
  • 실제로 쓰이지 않던 해(10^20) 대신 경(10^16)을 넣었습니다.

자릿수를 4로 나눠 단위를 고르던 방식은 8자리(1000만~9999만)를 억 단위로,
7자리 9999999를 반올림 뒤 천 단위로 잘못 골랐다. 유효숫자 두 자리로 먼저
반올림한 뒤 값 크기로 단위를 고르도록 바꾸고, 해 대신 경을 쓴다.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SOPICKS SOPICKS closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant