How to format currency so it will show up with the dollar sign and decimal point.

Cynthialiveshere
Cynthialiveshere used Ask the Experts™
on
I am writing a program but can't get the last 0 to add to it or dollar sign to show for the currency.  How do I write it and where do I put it in the coding?  Does it go under calculate or does it go under your DIM Statements.  Here is my DIM statements that I have:

    Private mdblsbtotal As Double
    Private mdblBaseRate As Double
    Private mdblStandard As Double = 84.5  (when I add the 0 after 5 it disappears)
    Private mdblDeluxe As Double = 104.5    
    Private mdblSuite As Double = 154.5
    Dim mdatbeginning, mdatlast As Date
    Dim mdblelapsed As Double

These are my boxes that need to have dollar signs and decimal points.  Actually it is giving me the decimal points but won't add the 0 to the end.  Ex. 84.5 instead of 84.50.  

        txtAnswerDays.Text = 0
        txtBaseAmount.Text = 0
        txtSubtotalAmount.Text = 0
        txtExtraGuestAmount.Text = 0
        txtRollawayAmount.Text = 0
        txtTotalAmount.Text = 0

One more thing that I am having a problem on is that when I add subtotal + rollaway + extraguest it adds the amount to the end of the total not adding into the total.  For example 84.50 is subtotal,  10.00 for extra guest and 5.00 for rollaway.  Instead of adding 84.50 + 10.00 + 5.00 = 99.50 it does this:  84.5105.  What am I doing wrong?

Here is my statement:
txtTotalAmount.Text = txtSubtotalAmount.Text + txtExtraGuestAmount.Text + txtRollawayAmount.Text

And if I have an Exit button how would that be written?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
format(YourCurrency,"$000,000,000")
GrahamSkanRetired
Top Expert 2012

Commented:
1. Use Format$(Amount, "Currency")
GrahamSkanRetired
Top Expert 2012

Commented:
2. You can use Dim Amount as Currency
3 Dim mdatbeginning, mdatlast As Date: This line will define mdatbeginning as a Variant
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
WHoa!

VB Has a specific format function just for you

FormatCurrency

More or less,  formatcurrency(variable, # of decimal places, True/False as to include leading zeros, true/false as to using Parens () for negative numbers)

Have fun

hope this helps.

Tim
GrahamSkanRetired
Top Expert 2012

Commented:
4 You can only assign values to constants when they are declared (up to VB6 anyway)
Private mdblDeluxe As Double = 104.5
you have to use strings to store this, but it will add the $ sign and 2 places after the decimal
FormatCurrency(TextBox1.Text, 2)
Retired
Top Expert 2012
Commented:
5 The Add of the Textbox values appears to be concatenating them instead. The + sign used to do both jobs up to about VB2. The concatenation operator (&) was introduced to help with this, but its functionality is still taken if all the operands could be strings as in:
txtTotalAmount.Text = txtSubtotalAmount.Text + txtExtraGuestAmount.Text + txtRollawayAmount.Text

Try txtTotalAmount.Text = Val(txtSubtotalAmount.Text) + Val(txtExtraGuestAmount.Text) + Val(txtRollawayAmount.Text)
6. You can also used the MaskedEdit control to display in particular formats

Author

Commented:
That format currency thing is not working.   Here is another example someone gave me:

txtSubtotal.Text = sbtotal.ToString("$#,###.#0")

but I don't know where to put it.  Does it go under DIM statements?  And also it is giving me an error:

txtSubtotal is not declared?
cynthialiveshere can be deleted.  did not know how to edit question to be more precise.  

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial