5 Replies Latest reply on Sep 16, 2007 3:51 PM by kglad

# math concatenating stings and numbers?

I am creating a fairly basic calculator that calculate stock option values and percentages etc,

I am having no problems changing a text field to a number and performing basic math but what I like to know is how to make it a little more dynamic.

I have three input textfields:

Number of options:
Grant Price:
Current stock price:

Then I've created a slider that the user can then increase/decrease the projected stock gain percentage from a range of -100 to 100 percent.

The results are four dynamic textfields that display the following results.

Project stock price:
Total stock value:
Total exercise cost:
Total options value:

Current everything works fine but here is where I want to be more dynamic. I would like when the user inputs their values the inputs textfields update to include "\$" "," and decimal points were applicable.

For example:
Number of options: user enters 10000 - field updates to 10,000.
Grant Price: user enters 25.50 - field updates to \$25.50
Current stock price: user enters 30.75 - field updates to \$30.75

Then the results would be displayed as follows.
(my math is not accurate)

Project stock price: \$35.25
Total stock value: \$375,250.25
Total exercise cost: \$250,250.00
Total options value: \$150,750.50

To sum it up how do I keep the math working and concatenate the "\$" "," "." into my numbers?

Any help with this would be greatly appreciated.

• ###### 1. Re: math concatenating stings and numbers?
my advice: keep the two (strings and numbers) separate. use two different variables for each output textfield. one that will contain your formatted string and the other, the number.

you can use functions to format your strings per your needs. the flash string methods are more than adequate for this.
• ###### 2. Re: math concatenating stings and numbers?

Could you possible give me one example on hown this is done and I'll try and figure out the rest of them on my own?
:

• ###### 4. Re: math concatenating stings and numbers?
Hmmmm??

Not having much luck figuring this out?

How would you apply those functions to the following:
• ###### 5. Re: math concatenating stings and numbers?
that's not good coding. use the onChanged method of textfields if you want to trigger code execution whenever a textfield changes.

to answer your question, if you want to format tsvText.text to be a number with commas use: