# 97.3x4 != 389.2?

**URL:** <https://forum.kirupa.com/t/97-3x4-389-2/2469>\
**Category:** Uncategorized\
**Created:** [March 28, 2002, 10:38pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469 "2002-03-28T22:38:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2002, 10:38pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/1 "2002-03-28T22:38:47Z")

</div>

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) {  
&nbsp &nbsp &nbsp &nbsp var c=random(1000)_0.1 //first number: \<1000 which i want with one decimal  
&nbsp &nbsp &nbsp &nbsp var d=random(100) //second number which i want \<100  
&nbsp &nbsp &nbsp &nbsp var e = “”; // name of the input box where the user writes the answer  
&nbsp &nbsp &nbsp &nbsp var res = c_d; //the result  
&nbsp &nbsp &nbsp &nbsp trace(res);  
}

Now i have a button that displays whether the answer is correct or not; the code is:  
on (release) {  
&nbsp &nbsp &nbsp &nbsp var certo; // dynamic text box variable which says whether the answer is correct or not  
&nbsp &nbsp &nbsp &nbsp if (res != e) {  
&nbsp &nbsp &nbsp &nbsp certo = “wrong…”;  
&nbsp &nbsp &nbsp &nbsp }  
&nbsp &nbsp &nbsp &nbsp else {certo = “right!”;  
&nbsp &nbsp &nbsp &nbsp }  
}

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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 28, 2002, 11:46pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/2 "2002-03-28T23:46:19Z")

</div>

Wild guess in nature : maybe it’s a rounding trouble. You could try to go a decimal further. But maybe that’s not the problem at all…

pom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 12:18am UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/3 "2002-03-29T00:18:32Z")

</div>

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!!  
🙂  
jeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 10:28am UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/4 "2002-03-29T10:28:25Z")

</div>

I suppose you could multiply your float by ten, multiply, and then divide the result by ten. That could solve your problem.

pom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 12:06pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/5 "2002-03-29T12:06:35Z")

</div>

someone reminded me that anything inside a textbox is a string; so, i should use parseFloat() when comparing results; it worked fine…so far

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 2:04pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/6 "2002-03-29T14:04:53Z")

</div>

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.  
🙂  
jeremy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 2:24pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/7 "2002-03-29T14:24:04Z")

</div>

as you can see in my original code i generated an integer and then divided it by 10, but the probs went on; this way, so far, i’ve no probs

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 29, 2002, 4:17pm UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/8 "2002-03-29T16:17:43Z")

</div>

Nice footer Sinfiniti! =)

Cheers!  
-Niann

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 12:29am UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/9 "2002-03-30T00:29:57Z")

</div>

What if you generate your numbers, multiply them and THEN divide by ten ? Won’t it work better ??

pom 0]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 30, 2002, 3:08am UTC](https://forum.kirupa.com/t/97-3x4-389-2/2469/10 "2002-03-30T03:08:02Z")

</div>

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.3_4);  
will show 389.2  
but, if you did this:  
for(ii=95;ii\<98;ii+=0.1){  
trace(ii_4);  
}  
where it should say 389.2 it says 389.1999999999, not a correct answer.  
bugs suck.  
🙂  
jeremy
