VBA/Excel/Access/Word/Date Functions/Number Format
Содержание
- 1 Characters for Creating Your Own Number Formats
- 2 Currency - The number is displayed with two decimal places, a thousand separator, and the currency symbol appropriate to the system locale.
- 3 Fixed - The number is displayed with two decimal places and at least one integer place.
- 4 Format(dblNumber "#####0")
- 5 Format(dblNumber "0.00")
- 6 Format(dblNumber "00")
- 7 Format(dblNumber "###,##0.00"): double
- 8 General Number - The number is displayed with no thousand separator.
- 9 On/Off - A non-zero number is displayed as On; a zero number is displayed as Off.
- 10 Percent - The number is displayed multiplied by ith two decimal places, and with a percent sign.
- 11 returns a currency formatted with four decimal places:
- 12 Scientific - The number is displayed in scientific notation.
- 13 Standard - The number is displayed with two decimal places, at least one integer place, and a thousand separator (when needed).
- 14 True/False - A non-zero number is displayed as True; a zero number is displayed as False.
- 15 Yes/No - A non-zero number is displayed as Yes; a zero number is displayed as No.
Characters for Creating Your Own Number Formats
<source lang="vb">
Character Explanation [None] Displays the number without any formatting. 0 Placeholder for a digit.
- Placeholder for a digit. If there"s no digit, VBA displays nothing.
. Placeholder for a decimal. % Placeholder for a percent character. , Thousand separator (depending on locale, a comma or a period).
- Time separator.
/ Date separator. E- E+ e- e+ Scientific format: E- or e- places a minus sign next to negative exponents. E+ or e+ places a minus sign next to negative exponents and places a plus sign next to positive exponents. - + $ () Displays a literal character. \[character] Displays the literal character. "[string]" Displays the literal character.
</source>
Currency - The number is displayed with two decimal places, a thousand separator, and the currency symbol appropriate to the system locale.
<source lang="vb">
Sub formatDemo3()
Debug.Print Format("12345", "Currency")
End Sub
</source>
Fixed - The number is displayed with two decimal places and at least one integer place.
<source lang="vb">
Sub formatDemo2()
Debug.Print Format("12345", "Fixed")
End Sub
</source>
Format(dblNumber "#####0")
<source lang="vb">
Sub numFormat()
dblNumber = 12345.678 Debug.Print dblNumber Debug.Print Format(dblNumber "#####0")
End Sub
</source>
Format(dblNumber "0.00")
<source lang="vb">
Sub numFormat()
dblNumber = 12345.678 Debug.Print dblNumber Debug.Print Format(dblNumber "0.00")
End Sub
</source>
Format(dblNumber "00")
<source lang="vb">
Sub numFormat()
dblNumber = 12345.678 Debug.Print dblNumber Debug.Print Format(dblNumber "000000.00")
End Sub
</source>
Format(dblNumber "###,##0.00"): double
<source lang="vb">
Sub numFormat()
dblNumber = 12345.678 Debug.Print dblNumber Debug.Print Format(dblNumber "###,##0.00")
End Sub
</source>
General Number - The number is displayed with no thousand separator.
<source lang="vb">
Sub formatDemo1()
Debug.Print Format("12345", "General Number")
End Sub
</source>
On/Off - A non-zero number is displayed as On; a zero number is displayed as Off.
<source lang="vb">
Sub formatDemo9()
Debug.Print Format("12345", "On/Off")
End Sub
</source>
Percent - The number is displayed multiplied by ith two decimal places, and with a percent sign.
<source lang="vb">
Sub formatDemo5()
Debug.Print Format("12345", "Percent")
End Sub
</source>
returns a currency formatted with four decimal places:
<source lang="vb">
Sub FormatDemo1()
Debug.Print Format("123456", "$00.0000")
End Sub
</source>
Scientific - The number is displayed in scientific notation.
<source lang="vb">
Sub formatDemo6()
Debug.Print Format("12345", "Scientific")
End Sub
</source>
Standard - The number is displayed with two decimal places, at least one integer place, and a thousand separator (when needed).
<source lang="vb">
Sub formatDemo4()
Debug.Print Format("12345", "Standard")
End Sub
</source>
True/False - A non-zero number is displayed as True; a zero number is displayed as False.
<source lang="vb">
Sub formatDemo8()
Debug.Print Format("12345", "True/False")
End Sub
</source>
Yes/No - A non-zero number is displayed as Yes; a zero number is displayed as No.
<source lang="vb">
Sub formatDemo7()
Debug.Print Format("12345", "Yes/No")
End Sub
</source>