This content has been marked as final. Show 22 replies
Okay, I've got this working for me:
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
are the display textfields (dynamic)
and mybutton is your button to press.
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!!!
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
That totally worked, THANK YOU SOOOOO MUCH!
I am very, VERY appreciative!
Thanks for your effort as well. Your script works as well! Even produces a $ sign in front of the amount, COOL!
THANKS A MILLION!!!
Is it possible to do the same thing but make the 'textbox2' amounts round up to the next $5 amount or no?
Input Text: 25.77
Text Field2: 30.00
Text Field3: 4.23
Possible or no?
PS. MAN, those scripts were great! LOL!!!
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.
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!
Input Text 1: 32.25
Text Field 2: 35.00
Text Field 3: 2.75
I was away for a bit there. The line:
adds the dollar.
just delete it or change it to
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:
Or to always round up to the next 5, like this:
So I would include that in the previous code that you sent me?
Yes, like this:
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?
That's just a way to round to multiples (or round up to multiples in your case).
Its probably easier to understand like this:
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.
Man, thank you so much for all your help! This was greatly appreciated and very informative.
So, what's wrong with this code? I'm trying to get it to round to the nearest 10th:
Sorry, I mean the nearest $10, not 10th.
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.
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:
but in the $5 example you used:
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.
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):
Look at the 'whatever' variable in the above function
its val/5 which is the same as val*.2 then its rounded (up) and multiplied by 5 again
its val/10 which is the same as val*.1 then its rounded (up) and multiplied by 10 again
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)
Ok...I think I can wrap my head around, LOL!
Thanks a lot for ALL your help...this was greatly appreciated!!!