LibreOffice 7.6 Help
Converts a numeric expression to a string, and then formats it according to the format that you specify.
Format(expression [, format As String]) As String
expression: Numeric expression that you want to convert to a formatted string.
format: String that specifies the format code for the number. If format is omitted, the Format function works like the LibreOffice Basic Str() function.
Text string.
The following list describes the codes that you can use for formatting a numeric expression:
0: If expression has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed.
If expression has fewer digits than the number of zeros in the format code, (on either side of the decimal), leading or trailing zeros are displayed. If the expression has more digits to the left of the decimal separator than the amount of zeros in the format code, the additional digits are displayed without formatting.
Decimal places in the expression are rounded according to the number of zeros that appear after the decimal separator in the format code.
#: If expression contains a digit at the position of the # placeholder in the format code, the digit is displayed, otherwise nothing is displayed at this position.
This symbol works like the 0, except that leading or trailing zeroes are not displayed if there are more # characters in the format code than digits in the expression. Only the relevant digits of the expression are displayed.
.: āĻĻāĻļāĻŽāĻŋāĻ āϏā§āĻĨāĻžāύāϧāĻžāϰāĻāĻāĻŋ āĻĻāĻļāĻŽāĻŋāĻ āĻŦāĻŋāĻāĻžāĻāĻā§āϰ āĻŦāĻžāĻŽ āĻ āĻĨāĻŦāĻž āĻĄāĻžāύā§āϰ āĻĻāĻļāĻŽāĻŋāĻ āϏā§āĻĨāĻžāύ āύāĻŋāϰā§āϧāĻžāϰāĻŖ āĻāϰ⧠āĻĨāĻžāĻā§āĨ¤
If the format code contains only # placeholders to the left of this symbol, numbers less than 1 begin with a decimal separator. To always display a leading zero with fractional numbers, use 0 as a placeholder for the first digit to the left of the decimal separator.
%: Multiplies the expressionby 100 and inserts the percent sign (%) where the expression appears in the format code.
E- E+ e- e+ : If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the expression is formatted in the scientific or exponential format. The letter E or e is inserted between the number and the exponent. The number of placeholders for digits to the right of the symbol determines the number of digits in the exponent.
āϝāĻĻāĻŋ āĻāĻāĻāĻŋ āϏā§āĻāĻ āĻāύāĻžāϤā§āĻŦāĻ āĻšā§ āϤāĻžāĻšāϞ⧠E-, E+, e-, e+ āϏāĻš āĻāĻāĻāĻŋ āϏā§āĻāĻā§āϰ āĻĒāĻŋāĻāύ⧠āϏāϰāĻžāϏāϰāĻŋ āĻāĻāĻāĻŋ āĻŦāĻŋā§ā§āĻ āĻāĻŋāĻšā§āύ āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšā§āĨ¤ āϝāĻĻāĻŋ āϏā§āĻāĻāĻāĻŋ āϧā§āĻŦāύāĻžāϤā§āĻŦāĻ āĻšā§ āϤāĻžāĻšāϞ⧠E+ āĻ āĻĨāĻŦāĻž e+ āϏāĻš āϏā§āĻāĻā§āϰ āĻĒāĻŋāĻāύ⧠āĻļā§āϧā§āĻŽāĻžāϤā§āϰ āĻāĻāĻāĻŋ āϝā§āĻ āĻāĻŋāĻšā§āύ āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšā§āĨ¤
The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #).
āϏāĻšāϏā§āϰ āĻāĻŦāĻ āĻĻāĻļāĻŽāĻŋāĻ āĻŦāĻŋāĻāĻžāĻāĻ āĻšāĻŋāϏā§āĻŦā§ āĻĒāϰā§āϝāĻžāϝāĻŧāĻāĻžāϞā§āϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϞāĻžāĻāĻž āĻāĻŋāϤā§āϤāĻŋāĻ āϏā§āĻāĻŋāĻ āĻāϰ āĻāĻĒāϰ āύāĻŋāϰā§āĻāϰāĻļā§āϞāĨ¤ āϝāĻāύ āĻāĻĒāύāĻŋ āĻŽā§āϞ āϏā§āϰā§āϏ āĻā§āĻĄā§ āϏāϰāĻžāϏāϰāĻŋ āĻāĻāĻāĻŋ āϏāĻāĻā§āϝāĻž āϏāύā§āύāĻŋāĻŦā§āĻļ āĻāϰāĻžāύā§āϰ āϏāĻŽā§, āϏāĻŦāϏāĻŽāϝāĻŧ āĻĻāĻļāĻŽāĻŋāĻ āĻŦāĻŋāĻā§āĻĻāĻ āĻšāĻŋāϏā§āĻŦā§ āĻāĻāĻāĻŋ āĻĒāϰā§āϝāĻžāϝāĻŧāĻāĻžāϞ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§āύāĨ¤ āĻĻāĻļāĻŽāĻŋāĻ āĻŦāĻŋāĻāĻžāĻāĻ āĻšāĻŋāϏā§āĻŦā§ āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻĒā§āϰāĻā§āϤ āĻ āĻā§āώāϰāĻāĻŋ āĻāĻĒāύāĻžāϰ āϏāĻŋāϏā§āĻā§āĻŽ āϏā§āĻāĻŋāĻ āĻ āϏāĻāĻā§āϝāĻžāϰ āĻŦāĻŋāύā§āϝāĻžāϏā§āϰ āĻāĻĒāϰ āύāĻŋāϰā§āĻāϰāĻļā§āϞāĨ¤
- + $ ( ) space: A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character.
āĻāĻāĻžāύ⧠āϤāĻžāϞāĻŋāĻāĻžāĻŦāĻĻā§āϧ āύ⧠āĻāĻŽāύ āĻ āĻā§āώāϰ āĻĒā§āϰāĻĻāϰā§āĻļāύā§āϰ āĻāύā§āϝ, āĻāĻāĻŋāϰ āĻ āĻŦāĻļā§āϝāĻ āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŦāĻŦāϰā§āϤ⧠āĻŦā§āϝāĻžāĻāĻļā§āϞā§āϝāĻžāĻļ (â\\) āĻĨāĻžāĻāϤ⧠āĻšāĻŦā§ āĻ āĻĨāĻŦāĻž āĻāĻāĻāĻŋ āĻāĻĻā§āϧā§āϤāĻŋ āĻāĻŋāĻšā§āύ (" ") āĻĻā§āĻŦāĻžāϰāĻž āĻāĻŦāĻĻā§āϧ āĻĨāĻžāĻāϤ⧠āĻšāĻŦā§āĨ¤
\ : The backslash displays the next character in the format code.
Characters in the format code that have a special meaning can only be displayed as literal characters if they are preceded by a backslash. The backslash itself is not displayed, unless you enter a double backslash (\\) in the format code.
āĻāĻā§āώāϰāĻŋāĻ āĻšāĻŋāϏā§āĻŦā§ āĻĒā§āϰāĻĻāϰā§āĻļāύā§āϰ āĻāύā§āϝ āĻ āĻā§āώāϰā§āϰ āĻĒā§āϰā§āĻŦā§ āĻ āĻŦāĻļā§āϝāĻ āĻāĻāĻāĻŋ āĻŦā§āϝāĻžāĻāϏā§āϞā§āϝāĻžāĻļ āĻŦāĻŋāĻļāĻŋāώā§āĻ āĻ āĻā§āώāϰ āĻšāϞ⧠āϤāĻžāϰāĻŋāĻ āĻāĻŦāĻ āϏāĻŽā§ āĻŦāĻŋāύā§āϝāĻžāϏ (a, c, d, h, m, n, p, q, s, t, w, y, /, :), āϏāĻāĻā§āϝāĻžāϏā§āĻāĻ-āĻŦāĻŋāύā§āϝāĻžāϏ āĻ āĻā§āώāϰ (#, 0, %, E, e, comma, period), āĻāĻŦāĻ āώā§āĻā§āϰāĻŋāĻ-āĻŦāĻŋāύā§āϝāĻžāϏ āĻ āĻā§āώāϰ (@, &, <, >, !)āĨ¤
You can also use the following predefined number formats. Except for "General Number", all of the predefined format codes return the number as a decimal number with two decimal places.
āĻāĻĒāύāĻŋ āϝāĻĻāĻŋ āĻĒā§āϰā§āĻŦāύāĻŋāϰā§āϧāĻžāϰāĻŋāϤ āĻŦāĻŋāύā§āϝāĻžāϏ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§āύ āϤāĻžāĻšāϞā§, āĻŦāĻŋāύā§āϝāĻžāϏā§āϰ āύāĻžāĻŽāĻāĻŋ āĻ āĻŦāĻļā§āϝāĻ āĻāĻĻā§āϧā§āϤāĻŋ-āĻāĻŋāĻšā§āύā§āϰ āĻŽāϧā§āϝ⧠āϰāĻžāĻāϤ⧠āĻšāĻŦā§āĨ¤
āϏāĻžāϧāĻžāϰāĻŖ āϏāĻāĻā§āϝāĻž: āϏāĻāĻā§āϝāĻž āĻĒā§āϰāĻŦā§āĻļā§āϰ āĻā§āϰāĻŽ āĻ āύā§āϏāĻžāϰ⧠āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšā§āĨ¤
āĻŽā§āĻĻā§āϰāĻž: āϏāĻāĻā§āϝāĻžāϰ āϏāĻžāĻŽāύ⧠āĻāĻāĻāĻŋ āĻĄāϞāĻžāϰ āĻāĻŋāĻšā§āύ ($) āϏāύā§āύāĻŋāĻŦā§āĻļ āĻāϰāĻžāύ⧠āĻšā§ āĻāĻŦāĻ āĻāύāĻžāϤā§āĻŦāĻ āϏāĻāĻā§āϝāĻž āĻŦāύā§āϧāύ⧠āĻĻā§āĻŦāĻžāϰāĻž āĻāĻŦāĻĻā§āϧ āĻāϰāĻž āĻšā§āĨ¤
āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ: āĻĻāĻļāĻŽāĻŋāĻ āĻŦāĻŋāĻāĻžāĻāĻā§āϰ āϏāĻžāĻŽāύ⧠āĻ āύā§āϤāϤ āĻāĻ āĻĄāĻŋāĻāĻŋāĻ āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšāĻŦā§āĨ¤
āĻāĻĻāϰā§āĻļ: āĻāĻāĻāĻŋ āϏāĻāĻā§āϝāĻž āĻšāĻžāĻāĻžāϰ āĻŦāĻŋāĻāĻžāĻāĻ āϏāĻš āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšā§āĨ¤
āĻļāϤāĻāϰāĻž: āϏāĻāĻā§āϝāĻžāĻāĻŋāĻā§ ā§§ā§Ļā§Ļ āĻĻā§āĻŦāĻžāϰāĻž āĻā§āĻŖ āĻāϰāĻž āĻšā§ āĻāĻŦāĻ āϏāĻāĻā§āϝāĻžāϰ āĻļā§āώ⧠āĻāĻāĻāĻŋ āĻļāϤāĻāϰāĻž āĻāĻŋāĻšā§āύ āϝā§āĻ āĻāϰāĻž āĻšā§āĨ¤
āĻŦā§āĻā§āĻāĻžāύāĻŋāĻ: āĻŦā§āĻā§āĻāĻžāύāĻŋāĻ āĻŦāĻŋāύā§āϝāĻžāϏ⧠āϏāĻāĻā§āϝāĻž āĻĒā§āϰāĻĻāϰā§āĻļāĻŋāϤ āĻšā§ (āϝā§āĻŽāύ, 1000 āĻāϰ āĻāύā§āϝ 1.00E+03 )āĨ¤
A format code can be divided into three sections that are separated by semicolons. The first part defines the format for positive values, the second part for negative values, and the third part for zero. If you only specify one format code, it applies to all numbers.
Sub ExampleFormat
MsgBox Format(6328.2, "##,##0.00")
REM āϏāĻŦāϏāĻŽā§ āĻĻāĻļāĻŽāĻŋāĻ āĻŽāĻžāύ āĻšāĻŋāϏā§āĻŦā§ āĻāĻāĻāĻŋ āĻāĻžāϰā§āϝāĻāĻžāϞ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠āĻĨāĻžāĻā§ āϝāĻāύ āĻāĻĒāύāĻŋ āĻŽā§āϞ āϏā§āϰā§āϏ āĻā§āĻĄā§ āϏāĻāĻā§āϝāĻž āϏāύā§āύāĻŋāĻŦā§āĻļ āĻāϰāĻžāύāĨ¤
REM āĻāĻĻāĻžāĻšāϰāĻŖ āĻšāĻŋāϏā§āĻŦā§ ā§Ŧ,ā§Šā§¨ā§Ž.⧍ā§Ļ āĻāĻāϰā§āĻā§ āϞā§āĻā§āϝāĻžāϞ, ā§Ŧ.ā§Šā§¨ā§Ž,⧍ā§Ļ āĻāĻžāϰā§āĻŽāĻžāύ āϞā§āĻā§āϝāĻžāϞ āĻĒā§āϰāĻĻāϰā§āĻļāύ āĻāϰ⧠āĻĨāĻžāĻā§āĨ¤
End Sub