PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
in 2 Decimal Places Code-VBForums
Results 1 to 3 of 3

Thread: in 2 Decimal Places Code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2003

    Question in 2 Decimal Places Code

    E = Val(Label10.Caption)
    Let F = E
    For v = 1 To Len(F)
    Let U = Mid(F, v, 1)
    If U = "." Then
    Let N = Right(Label10.Caption, 2)
    Let N = Left(N, 1)
    If N = "." Then Let Label10.Caption = "" & E & "0" Else Let Label10.Caption = "" & E
    Exit For
    If v = Len(F) Then Let Label10.Caption = "" & E & ".00"
    End If
    Next v
    This code is meant to convert a calculated label into pounds and 2 decimal places, and it partially work, but it does it to more that 2 dp.

    Can anyone fix it?

    Also can anyone explain this code to me set by step because I don't understand how it works?


  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Staffordshire, England
    (Let) was a keyword used by early versions of Basic, its not needed in VB.

    I hope you have declared all your variables before hand. Does it say Option Explicit at the top of your code window?

    The easiest way to calculate a number to 2 or more decimal places is to use the Round function. In your case:

    Label10.Caption = "" & Round(E, 2)

    (E) is the Number you want to calculate and 2 is the number of decimal places.

    You will find with Round that it rounds up the nearest number.

    e.g. Round("12.34836", 2) wil give 12.35.

    All this info is in the VB6 help, which you don't have.

  3. #3
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Manchester, UK
    heres a simple way
    VB Code:
    1. Label10.Caption = FormatCurrency(Val(Label10.Caption))


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