Hey all, ECMAScript/JavaScript/AS3에서 간단한 수학 연산을 수행 할 수없는 방법을 보여주기 위해 코드 샘플로 바로 넘어 갑시다 (AS3에서는 Number 클래스에 대해 'IEEE-754 배정 밀도 부동 소수점 숫자'를 사용합니다). 자바 스크립트에서 사용되는 것과 동일) ...왜 ECMAScript/ActionScript 3에서 부정확 한 부동 소수점 결과가 표시됩니까?
trace(1.1); //'1.1': Ok, fine, looks good.
trace(1.1*100); //'110.00000000000001': What!?
trace((1.1*100)/100); //'1.1': Brings it back to 1.1 (since we're apparently multiplying by *approximately* 100 and then dividing by the same *approximate* '100' amount)
trace(1.1*100-110); //'1.4210854715202004e-14': Proof that according to AS3, 1.1*100!=110 (i.e. this isn't just a bug in Number.toString())
trace(1.1*100==110); //'false': Even further proof that according to AS3, 1.1*100!=110
무엇을 제공합니까?
100 년대 있습니다 * 정확한. 근사치 인 1.1입니다 (2 진수로 1/10을 표현할 수있는 한정된 방법이 없습니다). 'trace (1.1)'이 올바른 이유는 십진수가 충분하기 때문입니다. 100을 곱하면 오류가 인쇄되는 부분으로 옮겨집니다. –