I am having a problem with displaying numbers as $154.50. Will not keep the 0 at the end. It drops off.

kevinswifecynthia used Ask the Experts™
I am having a problem with displaying numbers as $95.50.  For example: when I type in $95.50 it puts in 95.5.  I have 2 examples that someone gave me:

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

But when I put that in the Dim statement or put that in the calculate statement it tells me that sbtotal is not declared.  

This is what I have in my DIM statement:

Private mdblsbtotal As Double
    Private mdblsbtotal As Double
    Private mdblBaseRate As Double
    Private mdblStandard As Double = 95.5
    Private mdblDeluxe As Double = 164.5
    Private mdblSuite As Double = 194.5
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
txtSubtotal.Text = sbtotal.ToString("$#,###.##") '<here


Why not use the FormatCurrency function?

FormatCurrency(3212.4) -> $3,212.40

There are other paramaters you can use:
FormatCurrency(3212.4, 2, vbTrue, vbFalse, vbTrue)
paramater 1: expression
paramater 2: number of digits after the decimal
paramater 3: include a leading digit even if 0
paramater 4: use parentheses for negative numbers
paramater 5: group digits with comma (or period in other countries)

Dim a As Single
Dim mystr As String
a = 194.5
mystr = Format(a, "$##,##0.00")
text1.Text = mystr

This would do. By the way, why are you using DOUBLE's instead of SINGLE's? I think for most calculations, "Single" would be pretty enough for your values.
Author of the Year 2009

Moderator, my recommended disposition is:

    Split points between: dragontooth and eric0213

DanRollins -- EE database cleanup volunteer

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