PDA

View Full Version : Solved: change variable ; from 2000000 to $2,000,000



velohead
07-13-2010, 05:56 PM
Hi All,

I have a variable (variable_1) that has the value 2000000
This has come from an excel cell, containing the value 2000000

Now, I want to use the variable as a string, but in the format of $2,000,000


How would I convert the variable value to $2,000,000
Or would I need variable_2 based on variable_1
Not sure how to procede on this, would anyone offer a way forward.

velohead
07-13-2010, 06:34 PM
SOLVED....

it's
Variable_2 = Format(Variable_1, "Currency")

mbarron
07-13-2010, 06:36 PM
You could declare your variable as a Variant and do something like this:

Dim variable_1 as Variant
'some code
variable_1 = Format(variable_1, "$0,000")
I wouldn't recommend using this method. I would either use two variables or convert the variable_1 to the string when I was ready to use it.

Dim Variable_1 as Double, Variable_2 as String
'other code
Variable_2=Format(Variable_1,"$0,000")

velohead
07-13-2010, 07:01 PM
Yes, I prefer to use 2 variables, although a little longer.

I just noticed that "currency" adds the .00 to the end so I get $2,000,000.00

I think your solution will get rid of the .00 at the end.
Thanks.