[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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...


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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