i have a multiplication of 2 numbers and an input box so that the user can write the answer;the code for the numbers is:
on (release) {
        var c=random(1000)0.1 //first number: <1000 which i want with one decimal
        var d=random(100) //second number which i want <100
        var e = “”; // name of the input box where the user writes the answer
        var res = cd; //the result
        trace(res);
}
Now i have a button that displays whether the answer is correct or not; the code is:
on (release) {
        var certo; // dynamic text box variable which says whether the answer is correct or not
        if (res != e) {
        certo = “wrong…”;
        }
        else {certo = “right!”;
        }
}
I trace the result so i can easily compare results; but for some strange reason, one time and another the answer says diferent things from the true result, or, on another words, says wrong when should say right, like:
97.3x4=389.2
says its a wrong answer.
Where is the mistake?
Can anyone help?
flash has trouble with floating point numbers. if you doubt this, try this code on a movie clip:
onClipEvent(enterFrame){
trace(nNumber+=0.05);
}
as far as i can tell, this error shows up with any number smaller than 0.5!!
pom has the right idea. i had a project where i needed to increment by 0.25 and i kept having problems with it. what i ended up doing is incrementing by 1 and dividing the results by 4. it worked for that particular situation.
thanks niann!
anyways, like i said before. if you use integers and then divide that error doesn’t show up. this error only seems to show up when incrementing!!
try this:
for(ii=97;ii<100;ii+=0.1){
trace(ii);
}
the error shows up!
but
trace(97.34);
will show 389.2
but, if you did this:
for(ii=95;ii<98;ii+=0.1){
trace(ii4);
}
where it should say 389.2 it says 389.1999999999, not a correct answer.
bugs suck.
jeremy
Creating engaging and entertaining content for designers and developers since 1998.