math problem will Math.floor help

math problem will Math.floor help

Post by javma » Wed, 04 Feb 2004 23:27:13


I have the following code that at first sight should return a value of zero but does not always. What
can be done about this. The following code works as expected and will return a value of zero.
myVar2=-.25;
myVar=0;
mid=0;
button.onRelease = function(){
myVar=myVar+.05;
mid=myVar2+myVar;
integer=Math.floor(mid);
};


Can anyone tell me why the following code produces a result like 1.38777878078145e-17 instead of zero.

myVar2=-.1;
myVar=0;
mid=0;
button.onRelease = function(){
myVar=myVar+.01;
mid=myVar2+myVar;
integer=Math.floor(mid);
};
This problems seems to be beyond my knowledge. Any help so deeply appreciated. Thanks in advance.
 
 
 

math problem will Math.floor help

Post by kgla » Thu, 05 Feb 2004 00:36:30

1.38777878078145e-17 is zero to an accuracy of over 16 decimal places. integer of course, cannot be non-integer value, so i'm not sure what variable you found that has the decimal expression above.

 
 
 

math problem will Math.floor help

Post by javma » Thu, 05 Feb 2004 01:02:36

Thanks so much for the reply. I simply did not know that was a form of zero.

I would not have know that for years without your reply.
I am more hopeful now. I

have a function that looked at the integer value to see if it is zero and if it is some movie clips will be displayed. The following code has work well for me for quite some time, It was not until last night that I realized that it was not working for some possibilities.
_root.equalsign.onEnterFrame = function(){
if (integer==0){
this._visible=1;
_root.next_but._visible=1;
_root.Great_work._visible=1;

}
}
This function, seems to want to have the value of 0.
I tried the following but it did not work. Obviously I need to know more about these math functions
as this is completely foreign to me.

_root.equalsign.onEnterFrame = function(){
if (correct==0 || correct==1.38777878078145e-17){
this._visible=1;
_root.next_but._visible=1;
_root.Great_work._visible=1;

}
}
 
 
 

math problem will Math.floor help

Post by javma » Thu, 05 Feb 2004 01:17:05


Tuesday, February 03, 2004 4:00 PM
(New!)
sorry there is a mistake in my explanation as given before
if (correct==0 || correct==1.38777878078145e-17){
should have been
if (integer==0 || integer==1.38777878078145e-17){
(the code using correct is what I am using in my program, I changed it to integer here
so that it would be more clear.
The code I supplied should have read.



_root.equalsign.onEnterFrame = function(){
if (integer==0){
this._visible=1;
_root.next_but._visible=1;
_root.Great_work._visible=1;

}
}
This function, seems to want to have the value of 0.
I tried the following but it did not work. Obviously I need to know more about these math functions
as this is completely foreign to me.

_root.equalsign.onEnterFrame = function(){
if (integer==0 || integer==1.38777878078145e-17){
this._visible=1;
_root.next_but._visible=1;
_root.Great_work._visible=1;

}
}
 
 
 

math problem will Math.floor help

Post by javma » Thu, 05 Feb 2004 05:23:33

Many many thanks to kglad for help with this issue. You are truly a great blessing to this forum and have
been a real help to me personally in the past.

I wish that there was something that I could do for you in return.

I had to abandon the approach that I was taking and produced the result that I needed by a different
method.

There was something of a panic here as the program was about to be released in its Beta form
and then this problem showed up.
Once again many thanks from javman and his family.
 
 
 

math problem will Math.floor help

Post by kgla » Thu, 05 Feb 2004 10:28:15

oh, you're very welcome javaman (and family). i'm glad you were able to find a work-around.