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 maths / money calcualtions

Status
Not open for further replies.

shaun999

Technical User
Jun 11, 2001
4
GB
hi there,

i'm doing money calcualtions in flash
i had a problem with rounding down figures to decimal points, which someone answered & it's done now, thanks for that, the guy who answered!
but the new problem is when i have a calculation that is say 1.50 it will display it as 1.5 and the sums are in money so i was wondering if you can make flash leave the 0 on the end?
maybe someway that you can make the sums require 2 dec places even if it is .00

many thanks, shaun
 
hi shaun

I tested this using:

input textfield, variable "/:number"
dynamic textfield, variable "/:eek:utput"
button, actions:

[/code]on (keyPress &quot;<Enter>&quot;) {
/:numlength = /:number.length;
if (/:number<10 and /:numlength==3) {
/:eek:utput = /:number+&quot;0&quot;;
} else if (/:number<10 and /:numlength==1) {
/:eek:utput = /:number+&quot;.00&quot;;
} else if (/:number>=10 and /:numlength==4) {
/:eek:utput = /:number+&quot;0&quot;;
} else if (/:number>=10 and /:numlength==2) {
/:eek:utput = /:number+&quot;.00&quot;;
}
}[/code]



works for values less than 100, for values over 100 you would just have to add extra 'else if' statements.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
better give a very quick expo in case the above looks confusing.

Firstly, you eneter your value in the input box and hit enter, upon which the button actions are carried out to 'test' the value you have entered.

First of all the number you entered is checked as a string for length. So if you enter &quot;12.5&quot; then length would be 4 (includes the dot!).

This way, we know that any value under ten, written to two deciaml places should be 5 characters in length. As you mentioned, when flash calculates a value it leaves the zero's off the end, so there are only 2 variants which could not yield 2d.p.'s: for example 9.50 would become 9.5, and 9.00 would become 9. If your calculated value already has 2dp's, such as 9.51, we don't have to worry about it.

So the IF/else statements check that values under ten which have a character count of 3 (ie: 9.5) have a &quot;0&quot; added to them. Values under ten which have a character count of 1 (ie: 9) would have &quot;.00&quot; added to them.

Values above ten require a total of 5 characters if they are to be true 2dp values, so we check if the number that flash has created contains 4 (ie: 10.1) or just two characters (ie: 10), and add the extra digits accordingly.

Note we don't have to check for 2dp values, because if they exist they don't need changing. Also, we don't have to look for, say, 9. or 10. (ie: 2 character outputs under 10, or 3 character outputs under 100) because flash will never output an integer with the dot on the end, common sense stuff.

If you're still a bit bewildered, give me a shout.

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top