\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Matthew Perryman (PezMat)} \pdfinfo{ /Title (numeric-formats.pdf) /Creator (Cheatography) /Author (Matthew Perryman (PezMat)) /Subject (Numeric Formats Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{F4B084} \definecolor{LightBackground}{HTML}{FDF5EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Numeric Formats Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Matthew Perryman (PezMat)} via \textcolor{DarkBackground}{\uline{cheatography.com/26431/cs/7969/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Matthew Perryman (PezMat) \\ \uline{cheatography.com/pezmat} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 21st April, 2016.\\ Updated 12th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{x{5.5671 cm} x{8.9411 cm} x{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predefined Numeric Formats}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{G}} or {\bf{g}} & General Number\{\{nl\}\}Displays number with no thousand separator.\{\{nl\}\}For example, \seqsplit{`Strings.Format(\&H3FA}, "G")` or `String.Format("\{0:G\}", \&H3FA)` returns {\bf{1018}} & \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} {\bf{C}} or {\bf{c}} & Currency\{\{nl\}\}Displays number with thousand separator, if appropriate; displays two digits to the right of the decimal separator. Output is based on system locale settings.\{\{nl\}\}For example, \seqsplit{`Strings.Format(1234567}, "C")` or `String.Format("\{0:C\}", 1234567)` returns {\bf{£1,234,567.00}} & \{\{fa-star\}\} \tn % Row Count 22 (+ 14) % Row 2 \SetRowColor{LightBackground} {\bf{F}} or {\bf{f}} & Fixed\{\{nl\}\}Displays at least one digit to the left and two digits to the right of the decimal separator.\{\{nl\}\}For example, \seqsplit{`Strings.Format(1234567}, "F")` or `String.Format("\{0:F\}", 1234567)` returns {\bf{1234567.00}} & \{\{fa-star\}\} \tn % Row Count 33 (+ 11) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5671 cm} x{8.9411 cm} x{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predefined Numeric Formats (cont)}} \tn % Row 3 \SetRowColor{LightBackground} {\bf{N}} or {\bf{n}} & Standard\{\{nl\}\}Displays number with thousand separator, at least one digit to the left and two digits to the right of the decimal separator.\{\{nl\}\}For example, \seqsplit{`Strings.Format(1234567}, "N")` or `String.Format("\{0:N\}", 1234567)` returns {\bf{1,234,567.00}} & \{\{fa-star\}\} \tn % Row Count 12 (+ 12) % Row 4 \SetRowColor{white} {\bf{Percent}} & Displays number multiplied by 100 with a percent sign (\%) appended immediately to the right; always displays two digits to the right of the decimal separator.\{\{nl\}\}For example, \seqsplit{`Strings.Format(0.80345}, "Percent")` returns {\bf{80.35\%}} & \tn % Row Count 24 (+ 12) % Row 5 \SetRowColor{LightBackground} {\bf{P}} or {\bf{p}} & Displays number with thousandths 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.\{\{nl\}\}For example, \seqsplit{`Strings.Format(0.80345}, "P")` or `String.Format("\{0:P\}", 0.80345)` returns {\bf{80.35 \%}} & \{\{fa-star\}\} \tn % Row Count 39 (+ 15) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5671 cm} x{8.9411 cm} x{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predefined Numeric Formats (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{Scientific}} & Uses standard scientific notation, providing two significant digits.\{\{nl\}\}For example, \seqsplit{`Strings.Format(1234567}, "Scientific")` returns {\bf{1.23E+06}} & \tn % Row Count 7 (+ 7) % Row 7 \SetRowColor{white} {\bf{E}} or {\bf{e}} & Uses standard scientific notation, providing six significant digits.\{\{nl\}\}For example, \seqsplit{`Strings.Format(1234567}, "E")` or `String.Format("\{0:E\}", 1234567)` returns {\bf{1.234567E+006}}\{\{nl\}\}{\bf{Note:}} The case of the {\bf{e}} in the Format denotes the case of the {\bf{e}} in the output (i.e. using {\bf{e}} returns {\bf{1.234567e+006}}) & \{\{fa-star\}\} \tn % Row Count 23 (+ 16) % Row 8 \SetRowColor{LightBackground} {\bf{D}} or {\bf{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 ({\bf{Byte}}, {\bf{Short}}, {\bf{Integer}}, {\bf{Long}}) only.\{\{nl\}\}For example, \seqsplit{`Strings.Format(\&H7F}, "D")` or `String.Format("\{0:D\}", \&H7F)` returns {\bf{127}} & \tn % Row Count 37 (+ 14) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5671 cm} x{8.9411 cm} x{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predefined Numeric Formats (cont)}} \tn % Row 9 \SetRowColor{LightBackground} {\bf{X}} or {\bf{x}} & Displays number as a string that contains the value of the number in Hexadecimal (base 16) format. This option is supported for integral types ({\bf{Byte}}, {\bf{Short}}, {\bf{Integer}}, {\bf{Long}}) only.\{\{nl\}\}For example, `Strings.Format(127, "X")` or `String.Format("\{0:X\}", 127)` returns {\bf{7F}}\{\{nl\}\}{\bf{Note:}} The case of the {\bf{x}} in the Format denotes the case of the letters in the output (i.e. using {\bf{x}} returns {\bf{7f}}) & \tn % Row Count 20 (+ 20) % Row 10 \SetRowColor{white} {\bf{Yes/No}} & Displays No if number is 0; otherwise, displays Yes.\{\{nl\}\}For example, `Strings.Format(0, "Yes/No")` returns {\bf{No}} & \tn % Row Count 26 (+ 6) % Row 11 \SetRowColor{LightBackground} {\bf{True/\{\{nl\}\}False}} & Displays False if number is 0; otherwise, displays True.\{\{nl\}\}For example, `Strings.Format(1, "True/False")` returns {\bf{True}} & \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.5671 cm} x{8.9411 cm} x{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Predefined Numeric Formats (cont)}} \tn % Row 12 \SetRowColor{LightBackground} {\bf{On/Off}} & Displays Off if number is 0; otherwise, displays On.\{\{nl\}\}For example, `Strings.Format(1, "On/Off")` returns {\bf{On}} & \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{\{\{fa-star\}\} Digits after the formatting character determine the number of decimal places to output \newline For example, `Strings.Format(1234567, "C0")` or `String.Format("\{0:C0\}", 1234567)` returns `£1,234,567` \newline {\bf{The examples were created on a machine with 'English (United Kingdom)' Region settings}} \newline Smart Device Developer Notes \newline ~~~The {\bf{Yes/No}}, {\bf{True/False}}, and {\bf{On/Off}} formats are not supported.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{0}} & Digit placeholder\{\{nl\}\}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 \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} {\bf{\#}} & Digit placeholder\{\{nl\}\}Displays a digit or nothing. If the expression has a digit in the position where the {\bf{\#}} character appears in the format string, displays it; otherwise, displays nothing in that position \tn % Row Count 21 (+ 11) % Row 2 \SetRowColor{LightBackground} {\bf{.}} & Decimal placeholder\{\{nl\}\}The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. If the format expression contains only {\bf{\#}} 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 placeholder to the left of the decimal separator \tn % Row Count 42 (+ 21) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats (cont)}} \tn % Row 3 \SetRowColor{LightBackground} {\bf{\%}} & Percent placeholder\{\{nl\}\}Multiplies the expression by 100. The percent character (\%) is inserted in the position where it appears in the format string \tn % Row Count 8 (+ 8) % Row 4 \SetRowColor{white} {\bf{,}} & Thousand separator\{\{nl\}\}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 placeholders ({\bf{0}} or {\bf{\#}})\{\{nl\}\}For example, consider the three following format strings:\{\{nl\}\}\{\{fa-caret-right\}\}"\#,0.", which uses the thousands separator to format the number 100 million as the string "100,000,000"\{\{nl\}\}\{\{fa-caret-right\}\}"\#0,.", which uses scaling by a factor of one thousand to format the number 100 million as the string "100000"\{\{nl\}\}\{\{fa-caret-right\}\}"\#,0,.", which uses the thousands separator and scaling by one thousand to format the number 100 million as the string "100,000" \tn % Row Count 48 (+ 40) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats (cont)}} \tn % Row 5 \SetRowColor{LightBackground} {\bf{:}} & Time separator\{\{nl\}\}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 \tn % Row Count 15 (+ 15) % Row 6 \SetRowColor{white} {\bf{/}} & Date separator\{\{nl\}\}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 \tn % Row Count 30 (+ 15) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats (cont)}} \tn % Row 7 \SetRowColor{LightBackground} {\bf{E-}}, {\bf{E+}}, {\bf{e-}} or {\bf{e+}} & Scientific format\{\{nl\}\}If the format expression contains at least one digit placeholder ({\bf{0}} or {\bf{\#}}) to the left of {\bf{E-}}, {\bf{E+}}, {\bf{e-}} or {\bf{e+}}, the number is displayed in scientific format and `E` or `e` is inserted between the number and its exponent. The number of digit placeholders to the left determines the number of digits in the exponent. Use {\bf{E-}} or {\bf{e-}} to place a minus sign next to negative exponents. Use {\bf{E+}} or {\bf{e+}} to place a minus sign next to negative exponents and a plus sign next to positive exponents. You must also include digit placeholders to the right of this symbol to get correct formatting \tn % Row Count 32 (+ 32) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats (cont)}} \tn % Row 8 \SetRowColor{LightBackground} {\bf{-}}, {\bf{+}}, {\bf{\$}}, , {\bf{(}}, or {\bf{)}} & Literal characters\{\{nl\}\}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 ({\emph{**}}) or enclose it in double quotation marks (" ") \tn % Row Count 12 (+ 12) % Row 9 \SetRowColor{white} {\bf{\textbackslash{} }} & 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 ({\bf{\textbackslash{} }}). 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 backslashes ({\bf{\textbackslash{}\textbackslash{} }})\{\{nl\}\}Examples of characters that can't be displayed as literal characters are the date-formatting and time-formatting characters ({\bf{a}}, {\bf{c}}, {\bf{d}}, {\bf{h}}, {\bf{m}}, {\bf{n}}, {\bf{p}}, {\bf{q}}, {\bf{s}}, {\bf{t}}, {\bf{w}}, {\bf{y}}, {\bf{/}} and {\bf{:}}), the numeric-formatting characters ({\bf{\#}}, {\bf{0}}, {\bf{\%}}, {\bf{E}}, {\bf{e}}, comma and period), and the string-formatting characters ({\bf{@}}, {\bf{\&}}, {\bf{\textless{}}}, {\bf{\textgreater{}}} and {\bf{!}}) \tn % Row Count 49 (+ 37) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.4623 cm} x{8.8077 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{User-Defined Numeric Formats (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \{\{nobreak\}\}("{\emph{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 (")) \tn % Row Count 11 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Source}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{\{\{link="https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.format(v=vs.110).aspx"\}\}Strings.Format Method} \tn % Row Count 3 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}