This content has been marked as final.
Show 22 replies

1. COMPLEX MATH
0degreesK Mar 20, 2008 10:32 AM (in response to Mr.Wallace)Okay, I've got this working for me: 
2. Re: COMPLEX MATH
Greg Dove Mar 20, 2008 10:57 AM (in response to Mr.Wallace)This is close to what you want I think. The extra rounding seemed to be necessary, it will round to the nearest cent.
input1 is the name of the input text field
textfield2
textfield3
are the display textfields (dynamic)
and mybutton is your button to press. 
3. COMPLEX MATH
Mr.Wallace Mar 20, 2008 11:00 AM (in response to Mr.Wallace)WOW!
Ok, that was AMAZING!!! Thank you SO much, I appreciate that the efforts!
One question...when it does the subtraction it's giving me exact solutions, meaning, if the answer is $0.46, it gives me 0.46000000001 or whatever. Is that adjustable or no?
Even if it isn't...that was awesome. THANK YOU so much!!! 
4. Re: COMPLEX MATH
0degreesK Mar 20, 2008 11:02 AM (in response to Mr.Wallace)Mr. Wallace,
That's the problem my solution was running into. The code I posted above fixes that by:
1) Multiplying the long fraction (.466666666) by 100 giving 46.66666666
2) Applying the Math.ceil function to that number returning 46
3) Dividing that by 100 returning .46 
5. Re: COMPLEX MATH
Mr.Wallace Mar 20, 2008 11:19 AM (in response to Mr.Wallace)dex...YOU ROCK!!!
That totally worked, THANK YOU SOOOOO MUCH!
I am very, VERY appreciative! 
6. Re: COMPLEX MATH
Mr.Wallace Mar 20, 2008 11:22 AM (in response to Mr.Wallace)Hey GWD,
Thanks for your effort as well. Your script works as well! Even produces a $ sign in front of the amount, COOL!
THANKS A MILLION!!! 
7. COMPLEX MATH
Mr.Wallace Mar 20, 2008 11:27 AM (in response to Mr.Wallace)Is it possible to do the same thing but make the 'textbox2' amounts round up to the next $5 amount or no?
Example:
Input Text: 25.77
[CALCULATE]
Text Field2: 30.00
Text Field3: 4.23
Possible or no?
PS. MAN, those scripts were great! LOL!!! 
8. Re: COMPLEX MATH
Mr.Wallace Mar 20, 2008 12:02 PM (in response to 0degreesK)WHOA! WHOA! Got a problem here dex.
When I enter amounts ending in 1, for example 34.61, the rounded up number is correct but the subtraction is not. In the subtraction field it's saying that the answer is 0.4, but the answer should be 0.39.
Any ideas? 
9. COMPLEX MATH
Mr.Wallace Mar 20, 2008 12:12 PM (in response to Mr.Wallace)GWD,
Your code seems to do the trick as far as solving my above point of the amounts ending in 1 not adding up. One thing though...how can I get the $ symbol out of the input field once I press CALCULATE?
It was cool that you did that but I can't use that in my application.
:)
Also, if you had any ideas about how to round the numbers up to the next $5 amount, that you be cool too!
Example:
Input Text 1: 32.25
[CALCULATE]
Text Field 2: 35.00
Text Field 3: 2.75 
10. Re: COMPLEX MATH
Greg Dove Mar 20, 2008 12:40 PM (in response to Mr.Wallace)I was away for a bit there. The line:
input1.text="$"+val
adds the dollar.
just delete it or change it to
input1.text=val
to force the input to 2 decimal places (max)
It is possible to force formatting to be 2.10 instead of 2.1 for example, but that requires (a small amount of) extra code.
for rounding to the nearest 5 you could use a function like this:
function roundTo5(val:Number){
return (Math.round(val*.2)*5)
}

11. Re: COMPLEX MATH
Greg Dove Mar 20, 2008 12:42 PM (in response to Mr.Wallace)Or to always round up to the next 5, like this:
function roundTo5(val:Number){
return (Math.ceil(val*.2)*5)
} 
12. Re: COMPLEX MATH
Mr.Wallace Mar 20, 2008 12:44 PM (in response to Greg Dove)So I would include that in the previous code that you sent me? 

14. Re: COMPLEX MATH
Mr.Wallace Mar 20, 2008 1:55 PM (in response to Mr.Wallace)Wow...very, VERY cool!
Thank you again.
So what is it you're changing/adjusting when you want to round to the next $5? I'm assuming that you can do that for any value, yes? If I wanted to round to the next $2 increment or $10 increment I could just change all the 5's in the code to 2 or 10? 
15. Re: COMPLEX MATH
Greg Dove Mar 20, 2008 4:25 PM (in response to Mr.Wallace)That's just a way to round to multiples (or round up to multiples in your case).
Its probably easier to understand like this:
var val2=roundToWhatever(10,val);
function roundToWhatever(whatever:Number,val:Number){
return (Math.ceil(val/whatever)*whatever)
}
That's the example for 10. So if you put 6 in there instead of 10, it will round up to the next multiple of 6... 6,12,18 etc. 
16. Re: COMPLEX MATH
Mr.Wallace Mar 24, 2008 6:13 AM (in response to Greg Dove)Man, thank you so much for all your help! This was greatly appreciated and very informative.
THANKS!!! 
17. Re: COMPLEX MATH
Mr.Wallace Mar 24, 2008 6:30 AM (in response to Mr.Wallace)So, what's wrong with this code? I'm trying to get it to round to the nearest 10th:

18. Re: COMPLEX MATH
Mr.Wallace Mar 24, 2008 7:42 AM (in response to Mr.Wallace)Sorry, I mean the nearest $10, not 10th. 
19. Re: COMPLEX MATH
Greg Dove Mar 24, 2008 12:24 PM (in response to Mr.Wallace)You need to change the value that the function returns, changing its name alone will do nothing different. Or you can use the generic rounding up to multiples function I posted before.
function roundTo10(val:Number){
return (Math.ceil(val*.1)*10)
} 
20. Re: COMPLEX MATH
Mr.Wallace Mar 24, 2008 1:09 PM (in response to Greg Dove)So it's the RETURN section I'm screwing up. My question is, how are you coming up with the numbers you're using. For the $10 increments you used:
function roundTo10(val:Number){
return (Math.ceil(val*.1)*10)
}
but in the $5 example you used:
function roundTo5(val:Number){
return (Math.ceil(val*.2)*5)
}
Maybe I'm just not the greatest math person or something?! It seems like it should be easy. What if I wanted to round the nearest $2 for example...which two numbers would I use then? Obviously the last number would be *2 but what would the decimal be?
I apologize if I'm getting annoying, but I just want to make sure I understand completely. 
21. Re: COMPLEX MATH
Greg Dove Mar 24, 2008 1:28 PM (in response to Mr.Wallace)Its OK its not annoying, lol... just a failure in my communication I guess. I thought the function I posted earlier would make it clearer (I guess it didn't):
function roundToWhatever(whatever:Number,val:Number){
return (Math.ceil(val/whatever)*whatever)
}
Look at the 'whatever' variable in the above function
for 5:
its val/5 which is the same as val*.2 then its rounded (up) and multiplied by 5 again
for 10:
its val/10 which is the same as val*.1 then its rounded (up) and multiplied by 10 again
for 2:
its val/2 which is the same as val*.5 then its rounded (up) and multiplied by 2 again
using the function above, you can use one function and pass the rounding argument as well as the value to be rounded.
trace( roundToWhatever(2,3.5)) // shows 4 (3.5 rounded up to the next multiple of 2)
trace( roundToWhatever(10,3.5)) // shows 10 (3.5 rounded up to the next multiple of 10)
trace( roundToWhatever(5,3.5)) // shows 5 (3.5 rounded up to the next multiple of 5)

22. Re: COMPLEX MATH
Mr.Wallace Mar 24, 2008 2:02 PM (in response to Greg Dove)Ok...I think I can wrap my head around, LOL!
Thanks a lot for ALL your help...this was greatly appreciated!!!