Results 1 to 11 of 11

Thread: 2 decimal places

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Ireland
    Posts
    29
    Thanks for the reply Chris but i still can't get it to work.

    This is what I am trying to do.
    One text box has a decimal numer with unlimited decimal places.
    the other has a whole number and when i tab out of the box with the whole number it multiplies one by the other and displays the result in a seperate text box. i want the result to be 2 decimal places long in the result text box as i am dealing with currency,
    I would be grateful for any Help
    thanks
    Ciara
    Claire

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Try:
    Code:
    Formatcurrency(number,2)

  3. #3
    Megatron
    Guest
    There's also the Round function.
    Code:
    MyNum = Round(MyNum, 2)

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Ireland
    Posts
    29

    Thanks

    Thanks - greatly appreciated!!
    Claire

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Ireland
    Posts
    29
    where should i put that in?
    Under Lost Focus for when i tab out of the box?

    Claire
    Sorry I have only just started learning VB.

    thanks
    claire
    Claire

  6. #6
    Megatron
    Guest
    Yes, LostFocus will do.

  7. #7
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Megatron,

    I have a problem with the round function:

    Private Sub Command1_Click()
    MsgBox Round(1.5)
    MsgBox Round(2.5)
    End Sub

    Both return 2

  8. #8
    Megatron
    Guest
    Try

    MsgBox Round(1.5, 2)

    I'm sure if this'll work, because I do not have VB6 (but I've read about this function).

  9. #9
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    Originally posted by JamesM


    I have a problem with the round function:

    Is this a seperate question to Claire's?

    Megatron's code works for Claire's problem.

    If you are confused as to why both of your rounds return 2, then this is correct. Rounding numbers always moves a .5 value to the nearest even number. This is called rounding off. Rounding down is when the number always goes to the number below. i.e. 3.5 becomes 3, and rounding up goes to the nearest number above. All of these events only happen when the decimal is exactly .5

    I hope this clarifies things a bit,

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

  10. #10
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Meg and SD,

    Let me clarify:

    Code:
    Private Sub Command1_Click()
    MsgBox Round(10.115, 2)
    MsgBox Round(10.125, 2)
    
    'Both return 10.12 ?:eek: 
    End Sub
    But
    Code:
    Private Sub Command2_Click()
    MsgBox FormatCurrency(10.115, 2)
    MsgBox FormatCurrency(10.125, 2)
    
    'return the correct amounts of 10.12 And 10.13 respectively
    End Sub
    Statistically the round function works but this can create problems for currency calculations as in Claires case.

  11. #11
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453
    Ah! Sorry James, I didn't seewhat you were getting at originally.

    You are quite right, but then again so is Megatron.

    The round function is used in large systems (such as payroll) to try to statistically remove all the half-pennies that would be left in the system (ala Superman III)., Whilst this isn't really a problem (the money isn't actually transfered until the payroll is ran), it is considered an equitable solution.

    i.e. Rounding up favours the employees and rounding down favours the managers. I don't know if anyone ever really takes any of this stuff seriously, but I suppose some sad accountant somewhere probably does!!!

    For Caires purposes she could use either and argue the case, but it's probably best to avoid the argument and use FormatCurrency IMHO.

    Cheers,

    SD
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

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