• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

how can I change an entered currenct number from integer to comma seperated?


I need in Visual Basic that,
I want to change the display of a curreny entered by user, automatically to comma seperated one.

A field. User enters the numbers and I need to change it comma seperated with respect to it's .000 ones.
Steps      User Entered     Screen Out
=====      ============     ==========
Step 1:     1               1
Step 2:     12              12
Step 3:     120             120
Step 4:     1200            1,200
Step 5:     12000           12,000
Step 6:     120000          120,000
Step 7:     1200000         1,200,000
..... and so on...
thanx for your interest...
  • 3
  • 3
1 Solution
EgeAuthor Commented:
In Addition:

it will be done whenever onChange property...
Ryan ChongCommented:
Hi Ege,

Use the Format function in VB:

Dim iCur As Currency
iCur = 12532.646

Debug.Print Format$(iCur,"#,##0.00")

Ryan ChongCommented:
Use this if needed:

Public Sub CheckCurrency(ByVal txtControl As TextBox)
    txtControl = Trim$(txtControl)
    If Not IsNumeric(txtControl) Or Val(txtControl) < 0 Then
        txtControl = txtControl.Tag
        txtControl = Format(txtControl, "#,##0.00")
        txtControl.Tag = txtControl
    End If
End Sub
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

EgeAuthor Commented:
Himmm, I never use Format fot this purpose..

One more thing,
To change a currency, 1255650 to 1,255,650 (not .00)

Debug.Print Format$(iCur,"#,##0") is ok?
Debug.Print Format$(iCur,"#,###") ?

What is the main idea of #,### here?
if number is too big, with 12 digits for example,
do I need to increase number of #'s?

I will increase the point...

No, the # is only to represent the format and not the number of digits, so format(number,"#,###") indicates that every 3 numbers will be a comma.

Good luck
Ryan ChongCommented:
Yes, you can try: Debug.Print Format$(iCur,"#,##0"), it will remove the decimal place.

Use Debug.Print Format$(iCur,"#,##0") if you want to display 0 when a value is smaller than 0.

Use Debug.Print Format$(iCur,"#,###") will display nothing.

Use 0 is like placing the value with 0
EgeAuthor Commented:
Thanx for your all interest...
Best regards...
ryancys has been accepted... I works... Please answer my other question about adding two larg, very big number, grater than LONG...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now