매번 0.1을 뺀 간단한 간격이 있습니다.예기치 않은 값을주는 자바 스크립트 뺄셈
1
0.9
0.8
0.7000000000000001
0.6000000000000001
0.5000000000000001
0.40000000000000013
0.30000000000000016
0.20000000000000015
0.10000000000000014
1.3877787807814457e-16
가 왜이 미친 수를하고있다 :
function transition_opacity(div_id,opacity){
opacity = 1; //temporary test
var IntervId = setInterval(process_transition,30);
function process_transition(){
console.log(opacity); //check the value
opacity = opacity - 0.1
div_id.style.opacity = opacity;
if(opacity < 0.0){
rmv_div(div_id);
clear();
}
}
function clear(){
clearInterval(IntervId);
}
}
콘솔 로그 opacity
의 값이 표시됩니다 :하지만 연속 된 번호가 3 번 반복 후 이상한 간다 ...이 내가 무엇을 가지고 시퀀스 =/나에게 의미가있는 것 같아요 ... 그것은 잘 작동합니다. 0.8
아우, 부동 소수점 숫자입니다. 개자식들. 어쩌면이 도움이 될 것입니다 : http://floating-point-gui.de/ – acdcjunior
예 : http://stackoverflow.com/questions/963873/1-265-10000-126499-99999999999 –