디지털 추리 02 해설 · 0.30 대 0.30
한국어 해설
정답은 1번입니다. 화면에 표시한 문자열과 실제 비교에 쓰인 숫자가 다릅니다. JavaScript의 일반 숫자는 0.1과 0.2 같은 일부 소수를 이진수로 정확히 표현하지 못합니다. 0.1 + 0.2를 출력하면 0.30000000000000004이고 0.3과 엄격히 비교하면 거짓이지만, 둘 다 소수 둘째 자리로 표시하면 0.30입니다. 순서를 바꾸거나 0.30으로 표기해도 비교 결과는 같아요.
입력이 0.01시간 단위라면 처음부터 정수 10, 20, 30으로 저장해 10 + 20 = 30을 비교할 수 있습니다. 더 세밀한 입력을 받는 앱은 단위와 반올림 규칙을 먼저 정해야 합니다. 이 앱의 조건이 정확히 일치가 아니라 목표 이상이었다면 이 예시는 통과합니다.
화면 문자열이 같다고 목표 이상이라고 판단해서도 안 됩니다. 0.299, 0.300, 0.301은 둘째 자리까지 모두 0.30으로 보이지만 0.299는 0.30 미만입니다.
English explanation
Choice 1 is correct. The text on screen is rounded, but the comparison uses the original numbers. JavaScript prints 0.1 + 0.2 as 0.30000000000000004, which is not strictly equal to 0.3. Both nevertheless display as 0.30 to two decimal places. Reversing the addends or spelling the target 0.30 does not change that result.
If inputs are limited to hundredths of an hour, store integer hundredths from entry and compare 10 + 20 with 30. Finer inputs require a clear unit and rounding rule. A “meet or exceed” test would already pass this original example. Display strings are not a universal fix: 0.299, 0.300 and 0.301 all show as 0.30, but 0.299 is below the 0.30 minimum.
댓글
댓글 쓰기