How to work out an answer to 2 decimal places with VB 5?

[b][red]This message was edited by the dartsman at 2002-5-14 2:40:58[/red][/b][hr]
Does anyone know how to work out an answer to 2 decimal places with VB 5? I have been wondering this for some time. I thought that I might be able to use a If statement? It has to be for VB 5, not for VB 6. Someone told me that it was easy in VB 6, but I only have VB 5. Please help me.

The main problem is that I get the answer and then I need to make it work out an answer to 2 decimal places with VB 5. It must work out the answer then turn it to 2 decimal places (for example 10.01).

Thanks in Advance.

Dartsman


Comments

  • : [b][red]This message was edited by the dartsman at 2002-5-14 2:40:58[/red][/b][hr]
    : Does anyone know how to work out an answer to 2 decimal places with VB 5? I have been wondering this for some time. I thought that I might be able to use a If statement? It has to be for VB 5, not for VB 6. Someone told me that it was easy in VB 6, but I only have VB 5. Please help me.
    :
    : The main problem is that I get the answer and then I need to make it work out an answer to 2 decimal places with VB 5. It must work out the answer then turn it to 2 decimal places (for example 10.01).
    :
    : Thanks in Advance.
    :
    : Dartsman
    :
    :
    :

    In VB6 you use the Round function:

    MsgBox Round(123.456789, 2)

    I don't know if that works in VB5.

  • : : [b][red]This message was edited by the dartsman at 2002-5-14 2:40:58[/red][/b][hr]
    : : Does anyone know how to work out an answer to 2 decimal places with VB 5? I have been wondering this for some time. I thought that I might be able to use a If statement? It has to be for VB 5, not for VB 6. Someone told me that it was easy in VB 6, but I only have VB 5. Please help me.
    : :
    : : The main problem is that I get the answer and then I need to make it work out an answer to 2 decimal places with VB 5. It must work out the answer then turn it to 2 decimal places (for example 10.01).
    : :
    : : Thanks in Advance.
    : :
    : : Dartsman
    : :
    : :
    : :
    :
    : In VB6 you use the Round function:
    :
    : MsgBox Round(123.456789, 2)
    :
    : I don't know if that works in VB5.
    :
    :
    It should work fine. If my memory doesn't fail me, "Round" was present even in VB4.

    If it doesn't, use Format: it is a very bad programming practice, to use format to format a number into a formatted string, and auto type conversion to reconvert that thing into a number, but it works, and Format is one of the oldest functions VB has.
  • Could you please give this a try....

    **code starts**]
    Private Sub txtAmount_LostFocus()
    'forces 2 decimal places
    txtAmount.Text = Format(txtAmount.Text, "Fixed")
    End Sub
    **code ends**

    Hope this helps,
    Gordon
  • [b][red]This message was edited by the Plystire6754 at 2002-5-14 14:32:56[/red][/b][hr]
    [b][red]This message was edited by the Plystire6754 at 2002-5-14 14:31:9[/red][/b][hr]
    if it is just 2 decimals like money talk then use FORMAT!!!
    I don't CARE if it's bad practice, it's best, all you have to do is say
    (variable)=Format((variable),"currency") BIG NOTE: This WILL add a dollar sign I believe in which case you can change "currency" to "########.##" or however many #'s you want and with any commas you want.
    Now I may have the format of the Format wrong (hehe I said format twice...anyways) but if you look at the little pop up help thing that comes with it it will tell you where to put them.

    YES! THAT is the best way, in my opinion.

    And for those who even give a care the format function dates back to around QBasic (maybe even further) where it was called PRINT USING. =)

    Hope this helps.

    ~PlystirE~
    Alpha
    Kenny
    Animal
    (Say three times fast...NOTE: Not a tongue twister)





  • : [b][red]This message was edited by the Plystire6754 at 2002-5-14 14:32:56[/red][/b][hr]
    : [b][red]This message was edited by the Plystire6754 at 2002-5-14 14:31:9[/red][/b][hr]
    : if it is just 2 decimals like money talk then use FORMAT!!!
    : I don't CARE if it's bad practice, it's best, all you have to do is say
    : (variable)=Format((variable),"currency") BIG NOTE: This WILL add a dollar sign I believe in which case you can change "currency" to "########.##" or however many #'s you want and with any commas you want.
    : Now I may have the format of the Format wrong (hehe I said format twice...anyways) but if you look at the little pop up help thing that comes with it it will tell you where to put them.
    :
    : YES! THAT is the best way, in my opinion.
    :
    : And for those who even give a care the format function dates back to around QBasic (maybe even further) where it was called PRINT USING. =)
    :
    : Hope this helps.
    :
    : ~PlystirE~
    : Alpha
    : Kenny
    : Animal
    : (Say three times fast...NOTE: Not a tongue twister)
    :
    :
    :
    :
    :
    :

    Sure, and, if I'm not wrong, even BASIC for the Commodore 64 had it -I mean the dreaded PRINT USING (and I'm not joking - I'm talking about thingies like 'peek' and 'poke', for the few ppl who remember them).

    Besides, I have to agree. It's a crime, converting a number into a string to reconvert it back to a number, but, in VB it's the best way to do so (besides Round - perhaps).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories