Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flash mx calculation problem helppppppppp 1

Status
Not open for further replies.

mso2

Programmer
Mar 11, 2004
3
CA
var x=8.7

place a button with the following script

on(release){
trace(x--)
}

see that x=0.6999999 after 8 clicks
i have some calculations in my project
and i cant multiply by 10 and than to divid by 10 for every calculation

please help

thank you very much
 
Can you be more specific on what it is you need?

Do you need help writing a calculation that multiplies x by 10 and then divides the total by 10?

What exactly is it you need help writing?
 
on (release) {
var newX = int(((x--)*10)/10);
trace(newX);
}

this should round each iteration to the tenths, which should get you back to your .7

tigerjade :)

Always code as if the person who ends up maintaining your code will be a violent psychopath who knows where you live. -- Martin Golding


 
i'm having problems with some really basic calculations, i dont know whether it's a bug w/ flash, or if there's something wrong with my script.. the scenerio is like this, i have some buttons for the users to click on the following items:
0.01, 0.05, 0.10, 0.25, 1.00, 2.00, 5.00, 10.00, 20.00

when the total amount goes above 5, then 9 clicks of 0.05, 10 clicks of 0.10 are made, the amount is supposed to be 6.45, but it turns out to be 6.4499999999, i've tried all the possible combinations, it still turns out like this when the amount is >5, it's the same for 7.45, 8.45 and so on

could anyone pleaseeee tell me what's wrong? if it's the way how the calculations are done in flash MX? or is it possible to use the sum of the calculations up to 2 decimal places only so that the 6.4499999999 would show up as 6.45 instead? i cant think of any way to solve this problem, unless i force the calculations to add on the extra 0.0000000001

and it's weird that some code works fine in a function that i called, but the exact same code woudn't work in some other part, i had to copy & paste the part that worked to replace the part that wouldn't work, what could be the reasons causing all that problem? a bug within flash?!

thank you very much for helping me out!!
 
I would have advised math.round(your_result). It appears that the math.ceil() method does the same thing, the difference seems to be that math.ceil() always rounds up.

I didn't even know math.ceil() was there. Good to know! A star for Old.

JT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top