LibreOffice 24.8 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