Show Menu

Numeric Formats Cheat Sheet by

Characters used to export numbers in a desired format
c-     c-     format     formatting     vb

Predefined Numeric Formats

G or g
General Number
Displays number with no thousand separator.
For example, Strin­gs.F­or­mat­(&­H3FA, "­G") or Strin­g.F­orm­at(­"­{0:­G}", &H­3FA) returns 1018
C or c
Currency
Displays number with thousand separator, if approp­riate; displays two digits to the right of the decimal separator. Output is based on system locale settings.
For example, Strin­gs.F­or­mat­(12­34567, "­C") or Strin­g.F­orm­at(­"­{0:­C}", 1234567) returns £1,2­34,­567.00
F or f
Fixed
Displays at least one digit to the left and two digits to the right of the decimal separator.
For example, Strin­gs.F­or­mat­(12­34567, "­F") or Strin­g.F­orm­at(­"­{0:­F}", 1234567) returns 1234­567.00
N or n
Standard
Displays number with thousand separator, at least one digit to the left and two digits to the right of the decimal separator.
For example, Strin­gs.F­or­mat­(12­34567, "­N") or Strin­g.F­orm­at(­"­{0:­N}", 1234567) returns 1,23­4,5­67.00
Perc­ent
Displays number multiplied by 100 with a percent sign (%) appended immedi­ately to the right; always displays two digits to the right of the decimal separator.
For example, Strin­gs.F­or­mat­(0.8­0345, "­Per­cen­t") returns 80.35%
P or p
Displays number with thousa­ndths separator multiplied by 100 with a percent sign (%) appended to the right and separated by a single space; always displays two digits to the right of the decimal separator.
For example, Strin­gs.F­or­mat­(0.8­0345, "­P") or Strin­g.F­orm­at(­"­{0:­P}", 0.80345) returns 80.35 %
Scientific
Uses standard scientific notation, providing two signif­icant digits.
For example, Strin­gs.F­or­mat­(12­34567, "­Sci­ent­ifi­c") returns 1.23­E+06
E or e
Uses standard scientific notation, providing six signif­icant digits.
For example, Strin­gs.F­or­mat­(12­34567, "­E") or Strin­g.F­orm­at(­"­{0:­E}", 1234567) returns 1.234567E+006
Note: The case of the e in the Format denotes the case of the e in the output (i.e. using e returns 1.23­456­7e+­006)
D or d
Displays number as a string that contains the value of the number in Decimal (base 10) format. This option is supported for integral types (Byte, Short, Inte­ger, Long) only.
For example, Strin­gs.F­or­mat­(&H7F, "­D") or Strin­g.F­orm­at(­"­{0:­D}", &H7F) returns 127
X or x
Displays number as a string that contains the value of the number in Hexade­cimal (base 16) format. This option is supported for integral types (Byte, Short, Inte­ger, Long) only.
For example, Strin­gs.F­or­mat­(127, "­X") or Strin­g.F­orm­at(­"­{0:­X}", 127) returns 7F
Note: The case of the x in the Format denotes the case of the letters in the output (i.e. using x returns 7f)
Yes/No
Displays No if number is 0; otherwise, displays Yes.
For example, Strin­gs.F­or­mat(0, "­Yes­/No­") returns No
True/
False
Displays False if number is 0; otherwise, displays True.
For example, Strin­gs.F­or­mat(1, "­Tru­e/F­als­e") returns True
On/Off
Displays Off if number is 0; otherwise, displays On.
For example, Strin­gs.F­or­mat(1, "­On/­Off­") returns On
Digits after the formatting character determine the number of decimal places to output
For example, Strin­gs.F­or­mat­(12­34567, "­C0") or Strin­g.F­orm­at(­"­{0:­C0}­", 1234567) returns £1,23­4,567
The examples were created on a machine with 'English (United Kingdom)' Region settings
Smart Device Developer Notes
 ­ ­ The Yes/­No, True­/Fa­lse, and On/Off formats are not supported.

User-D­efined Numeric Formats

0
Digit placeholder
Displays a digit or a zero. If the expression has a digit in the position where the zero appears in the format string, display it; otherwise, displays a zero in that position
#
Digit placeholder
Displays a digit or nothing. If the expression has a digit in the position where the # character appears in the format string, displays it; otherwise, displays nothing in that position
.
Decimal placeholder
The decimal placeh­older determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only # characters to the left of this symbol; numbers smaller than 1 begin with a decimal separator. To display a leading zero displayed with fractional numbers, use zero as the first digit placeh­older to the left of the decimal separator
%
Percent placeholder
Multiplies the expression by 100. The percent character (%) is inserted in the position where it appears in the format string
,
Thousand separator
The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. Standard use of the thousand separator is specified if the format contains a thousand separator surrounded by digit placeh­olders (0 or #)
For example, consider the three following format strings:
"#,0.", which uses the thousands separator to format the number 100 million as the string "100,000,000"
"#0,.", which uses scaling by a factor of one thousand to format the number 100 million as the string "100000"
"#,0,.", which uses the thousands separator and scaling by one thousand to format the number 100 million as the string "­100­,00­0"
:
Time separator
In some locales, other characters may be used to represent the time separator. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in formatted output is determined by your system settings
/
Date separator
In some locales, other characters may be used to represent the date separator. The date separator separates the day, month, and year when date values are formatted. The actual character used as the date separator in formatted output is determined by your system settings
E-, E+, e- or e+
Scientific format
If the format expression contains at least one digit placeh­older (0 or #) to the left of E-, E+, e- or e+, the number is displayed in scientific format and E or e is inserted between the number and its exponent. The number of digit placeh­olders to the left determines the number of digits in the exponent. Use E- or e- to place a minus sign next to negative exponents. Use E+ or e+ to place a minus sign next to negative exponents and a plus sign next to positive exponents. You must also include digit placeh­olders to the right of this symbol to get correct formatting
-, +, $, , (, or )
Literal characters
These characters are displayed exactly as typed in the format string. To display a character other than one of those listed, precede it with a backslash (**) or enclose it in double quotation marks (" ")
\
Displays the next character in the format string. To display a character that has special meaning as a literal character, precede it with a backslash (\ ). The backslash itself isn't displayed. Using a backslash is the same as enclosing the next character in double quotation marks. To display a backslash, use two backsl­ashes (\\ )
Examples of characters that can't be displayed as literal characters are the date-f­orm­atting and time-f­orm­atting characters (a, c, d, h, m, n, p, q, s, t, w, y, / and :), the numeri­c-f­orm­atting characters (#, 0, %, E, e, comma and period), and the string­-fo­rma­tting characters (@, &, <, > and !)
("ABC")
Displays the string inside the double quotation marks (" "). To include a string in the style argument from within code, you must use Chr(34) to enclose the text (34 is the character code for a quotation mark ("))

Download the Numeric Formats Cheat Sheet

4 Pages
//media.cheatography.com/storage/thumb/pezmat_numeric-formats.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Slack messages formatting Cheat Sheet
          Date/Time Formats Cheat Sheet

          More Cheat Sheets by PezMat

          Date/Time Formats Cheat Sheet