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

# Thread: £ in 2 Decimal Places Code

1. ## £ in 2 Decimal Places Code

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
Else
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?

Thanks

2. (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. heres a simple way
VB Code:
`Label10.Caption = FormatCurrency(Val(Label10.Caption))`

casey.

#### Posting Permissions

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

Featured