Results 1 to 8 of 8

Thread: Decimal Place Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    I would like to have results show in my txt box with no more than 2 places after decimal (0.00). I tried selecting the data format property on the txt box and setting it to how I would like, but it doesn't seem to do anything. Ideas?

    Thank You! (again)

  2. #2
    Junior Member
    Join Date
    Oct 2000
    Posts
    18
    Code:
    dVal = 3.141592654
    Text1.Text = Format(dVal,"#,##0.00")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    I'm confused.

    1. What does the "dVal = 3.141592654" represent/do

    2. Where does this go?

  4. #4
    Guest
    dVal = 3.141592654
    Text1.Text = Format(dVal,"#,##0.00")

    dVal can be Integer.

    Text1.Text = Format(dVal,"#,##0.00")
    becomes the result.

    Format = Format function (take a look in your VB Help File or MSDN Library for "format function".)

    Copy and then paste it into the Form_Load event or wherever you want.

    Basically, dVal is the variable which is holding the number and then it is formated to do what you want: get only 2 decimal places and that's it.

    So your code would look like this:

    Code:
    Private Sub Form_Load()
    Dim dVal As Integer
    dVal = 3.141592654
    Msgbox Format(dVal,"#,##0.00")
    End Sub
    Hope that explains a bit more.
    Did I confuse you a bit more?
    It's not the best explaination, but may get you somewhere.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    Maybe I'm explaining this wrong.
    This is what I have now:

    txtAve.Text = (Val(txt1a) + Val(txt2a)) / (Val(txt1) + Val(txt2))

    Currently when you click the cmd button that calculates txtAve's result, you get multiple positions past the decimal. I want to limit how many spaces.

    I'm sorry if I've made this so confusing.

    Thanks again.

  6. #6
    Guest
    Do you want to round the final answer?
    Because you can use the Round function to do it.

    Code:
    'Round(number,decimal place)
    '=Round(number,2)
    txtAve.Text = Round((Val(txt1a) + Val(txt2a)) / (Val(txt1) + Val(txt2)), 2)
    So it will be rounded and only show the number and 2 decimal places.

  7. #7
    Junior Member
    Join Date
    Nov 2000
    Posts
    20
    Why wouldn't you just declare the variable that the txtbox is outputting as a Double?

  8. #8
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    You may could use this if you don't need it rounded

    txtAve = Format(txtAve, "Fixed")

    This would give you two decimal places.

    JO

    [Edited by joltremari on 11-20-2000 at 05:28 PM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width