|
-
Jun 16th, 2010, 07:29 AM
#1
Thread Starter
Fanatic Member
Formatting Numbers to Display A Certain Way in Labels
I would like to know how to code a number that ends with "000000" and display that particular number in a label as "# MIL".
Like, say, if I had to enter in a text box the number 56000000, then instead of displaying the number as "56000000" in the label, it should display as "56 MIL" (MIL meaning million).
Also, for numbers higher than 9999 but lower than 1000000, the number should display a comma to distinguish the thousands. How do I do this, along with the "MIL" scenario?
-
Jun 16th, 2010, 07:39 AM
#2
Re: Formatting Numbers to Display A Certain Way in Labels
Many uses for the Format$ function.
Code:
Dim Mega As Long
Dim Num As Long
Mega = 10 ^ 6
Num = 1550 * Mega
Debug.Print Format$(Num / Mega, "# Mil")
Debug.Print Format$(Num, "###,##0")
Debug.Print Format$(Num / Mega, "###,##0 MIL")
-
Jun 16th, 2010, 08:02 AM
#3
Re: Formatting Numbers to Display A Certain Way in Labels
This may help:
Code:
Text1.Text = "56000000"
'Text1.Text = "56000012"
'Text1.Text = "12345"
Dim n As Long
n = Val(Text1.Text)
Label1.Caption = Format(n, IIf(n <> 0 And n Mod 1000000 = 0, "#,,"" MIL""", "#,##0"))
Code:
56 MIL
56,000,012
12,345
Last edited by anhn; Jun 16th, 2010 at 09:02 AM.
Reason: Remove Abs()
-
Jun 16th, 2010, 08:47 AM
#4
Re: Formatting Numbers to Display A Certain Way in Labels
If IsNumeric(Text1.Text) Then Label1.Caption = Int(Text1.Text / 10000@) / 100 & " MIL"
"56000000" -> 56 MIL
"56000012" -> 56 MIL
"56120000" -> 56,12 MIL
"12345" -> 0,01 MIL
This is what I understood from the last paragraph of the OP, don't know whether it is wanted this way or not.
Last edited by Merri; Jun 16th, 2010 at 09:19 AM.
Reason: Changed datatype
-
Jun 17th, 2010, 02:04 AM
#5
Re: Formatting Numbers to Display A Certain Way in Labels
 Originally Posted by JonSea31
I would like to know how to code a number that ends with "000000" and display that particular number in a label as "# MIL".
Like, say, if I had to enter in a text box the number 56000000, then instead of displaying the number as "56000000" in the label, it should display as "56 MIL" (MIL meaning million).
Also, for numbers higher than 9999 but lower than 1000000, the number should display a comma to distinguish the thousands. How do I do this, along with the "MIL" scenario?
I understand differently.
-
Jun 18th, 2010, 06:48 PM
#6
Thread Starter
Fanatic Member
Re: Formatting Numbers to Display A Certain Way in Labels
 Originally Posted by anhn
This may help:
Code:
Text1.Text = "56000000"
'Text1.Text = "56000012"
'Text1.Text = "12345"
Dim n As Long
n = Val(Text1.Text)
Label1.Caption = Format(n, IIf(n <> 0 And n Mod 1000000 = 0, "#,,"" MIL""", "#,##0"))
Code:
56 MIL
56,000,012
12,345
And what about percentages? I would like to learn to format percentages (with a percent sign).
Last edited by JonSea31; Jun 18th, 2010 at 08:04 PM.
-
Jun 18th, 2010, 08:15 PM
#7
Re: Formatting Numbers to Display A Certain Way in Labels
MsgBox (PartValue / TotalValue * 100) & " %"
Note that this will generate an error of TotalValue would be 0.
-
Jun 18th, 2010, 08:16 PM
#8
Thread Starter
Fanatic Member
Re: Formatting Numbers to Display A Certain Way in Labels
I was able to figure out the Billion scenario, but it can only go so far with the Long command. What would I have to use instead of "Long" to accommodate larger numbers?
-
Jun 18th, 2010, 08:20 PM
#9
Thread Starter
Fanatic Member
Re: Formatting Numbers to Display A Certain Way in Labels
 Originally Posted by Merri
MsgBox (PartValue / TotalValue * 100) & " %"
Note that this will generate an error of TotalValue would be 0.
Actually, I was thinking about reading a number from a text file and displaying it in percentage form.
-
Jun 18th, 2010, 09:00 PM
#10
Re: Formatting Numbers to Display A Certain Way in Labels
(EDIT: You may figure out anything yourself)
by searching VB Help on Format() function on how to define FormatString.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|