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?
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")
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
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.
Re: Formatting Numbers to Display A Certain Way in Labels
Quote:
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.
Re: Formatting Numbers to Display A Certain Way in Labels
Quote:
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).
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.
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?
Re: Formatting Numbers to Display A Certain Way in Labels
Quote:
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.
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.