Format Function

Converts a numeric expression to a string, and then formats it according to the format that you specify.

Syntax:


Format(expression [, format As String]) As String

Parameters:

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.

Return value:

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 #).

αž€αžΆαžšβ€‹αž”αŸ’αžšαžΎβ€‹αž…αŸ†αžŽαž»αž…β€‹αž˜αž½αž™αž‡αžΆβ€‹αž’αŸ’αž“αž€β€‹αž”αŸ†αž”αŸ‚αž€β€‹αžαŸ’αž‘αž„αŸ‹αž–αžΆαž“αŸ‹ αž“αž·αž„β€‹αž‘αžŸαž—αžΆαž‚ αž‚αžΊβ€‹αž’αžΆαžŸαŸ’αžšαŸαž™β€‹αž‘αŸ…β€‹αž›αžΎβ€‹αž€αžΆαžšβ€‹αž€αŸ†αžŽαžαŸ‹β€‹αžαŸ†αž”αž“αŸ‹Β αŸ” αžαŸ‚αž„β€‹αžαŸ‚β€‹αž”αŸ’αžšαžΎαž…αŸ†αžŽαž»αž…β€‹αž‡αžΆβ€‹αžŸαž‰αŸ’αž‰αžΆβ€‹αž‘αžŸαž—αžΆαž‚ αž–αŸαž›β€‹αž’αŸ’αž“αž€β€‹αž”αž‰αŸ’αž…αžΌαž›β€‹αž…αŸ†αž“αž½αž“β€‹αž˜αž½αž™β€‹αžŠαŸ„αž™β€‹αž•αŸ’αž‘αžΆαž›αŸ‹αž€αŸ’αž“αž»αž„αž€αžΌαžŠ BasicΒ αŸ” αžαž½β€‹αž’αž€αŸ’αžŸαžšβ€‹αž–αž·αžαž”αŸ’αžšαžΆαž€αžŠβ€‹αžŠαŸ‚αž›β€‹αž”αžΆαž“β€‹αž”αž„αŸ’αž αžΆαž‰β€‹αž‡αžΆβ€‹αžŸαž‰αŸ’αž‰αžΆβ€‹αž‘αžŸαž—αžΆαž‚β€‹ αž’αžΆαžŸαŸ’αžšαŸαž™β€‹αž›αžΎβ€‹αž‘αŸ’αžšαž„αŸ‹β€‹αž‘αŸ’αžšαžΆαž™β€‹αžšαž”αžŸαŸ‹β€‹αž…αŸ†αž“αž½αž“β€‹ αž€αŸ’αž“αž»αž„β€‹αž€αžΆαžšβ€‹αž€αŸ†αžŽαžαŸ‹β€‹αž”αŸ’αžšαž–αŸαž“αŸ’αž’β€‹αžšαž”αžŸαŸ‹β€‹αž’αŸ’αž“αž€Β αŸ”

- + $ ( ) 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 αžŸαž‰αŸ’αž‰αžΆβ€‹αž€αŸ’αž”αŸ€αžŸ αžŸαž‰αŸ’αž‰αžΆβ€‹αž…αž»αž…) αž“αž·αž„β€‹αžαž½β€‹αž’αž€αŸ’αžŸαžšβ€‹αžŠαŸ‚αž›β€‹αž˜αžΆαž“β€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αž‡αžΆβ€‹αžαŸ’αžŸαŸ‚β€‹αž’αž€αŸ’αžŸαžš (@, &, <, >, !)Β αŸ”

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.

αž”αŸ’αžšαžŸαž·αž“β€‹αž”αžΎβ€‹αž’αŸ’αž“αž€β€‹αž”αŸ’αžšαžΎβ€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αž€αŸ†αžŽαžαŸ‹β€‹αž‡αžΆβ€‹αž˜αž»αž“ αžˆαŸ’αž˜αŸ„αŸ‡β€‹αž“αŸƒβ€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αžαŸ’αžšαžΌαžœβ€‹αžαŸ‚β€‹αžŸαŸ’αžαž·αžβ€‹αž“αŸ…β€‹αž€αŸ’αž“αž»αž„β€‹αžŸαž‰αŸ’αž‰αžΆβ€‹αžŸαž˜αŸ’αžšαž„αŸ‹ ("")Β αŸ”

αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αž€αŸ†αžŽαžαŸ‹β€‹αž‡αžΆβ€‹αž˜αž»αž“

αž›αŸαžβ€‹αž‘αžΌαž‘αŸ…β€‹ αŸ– αž›αŸαžβ€‹αžαŸ’αžšαžΌαžœβ€‹αž”αžΆαž“β€‹αž”αž„αŸ’αž αžΆαž‰β€‹αžŠαžΌαž…β€‹αžŠαŸ‚αž›β€‹αž”αžΆαž“β€‹αž”αž‰αŸ’αž…αžΌαž›Β αŸ”

αžšαžΌαž”αž·αž™αž”αŸαžŽαŸ’αžŽ αŸ– αž”αž‰αŸ’αž…αžΌαž›β€‹αžŸαž‰αŸ’αž‰αžΆβ€‹αžŠαž»αž›αŸ’αž›αžΆαžšβ€‹αž–αžΈβ€‹αž˜αž»αžβ€‹αž›αŸαž αž“αž·αž„β€‹αžŠαžΆαž€αŸ‹β€‹αž›αŸαžβ€‹αž’αžœαž·αž‡αŸ’αž‡αž˜αžΆαž“β€‹αž€αŸ’αž“αž»αž„β€‹αžœαž„αŸ‹β€‹αž€αŸ’αžšαž…αž€Β αŸ”

αž”αžΆαž“β€‹αž‡αž½αžŸαž‡αž»αž›β€‹ αŸ– αž”αž„αŸ’αž αžΆαž‰β€‹αž™αŸ‰αžΆαž„β€‹αž αŸ„αž…β€‹αž˜αž½αž™β€‹αžαž½αž›αŸαž αž“αŸ…β€‹αž–αžΈβ€‹αž˜αž»αžβ€‹αž’αŸ’αž“αž€β€‹αžαžŽαŸ’αžŒβ€‹αž…αŸ‚αž€β€‹αž‘αžŸαž—αžΆαž‚Β αŸ”

αžŸαŸ’αžαž„αŸ‹αžŠαžΆαžšβ€‹ αŸ– αž”αž„αŸ’αž αžΆαž‰β€‹αž›αŸαžβ€‹αž‡αžΆαž˜αž½αž™β€‹αž’αŸ’αž“αž€β€‹αž”αŸ†αž”αŸ‚αž€β€‹αžαŸ’αž‘αž„αŸ‹β€‹αž–αžΆαž“αŸ‹Β αŸ”

αž—αžΆαž‚αžšαž™ αŸ– αž‚αž»αžŽβ€‹αž›αŸαžβ€‹αž“αžΉαž„ ៑០០ αžšαž½αž…β€‹αž”αž“αŸ’αžαŸ‚αž˜β€‹αžŸαž‰αŸ’αž‰αžΆβ€‹αž—αžΆαž‚αžšαž™β€‹αž“αŸ…β€‹αžαžΆαž„β€‹αž…αž»αž„β€‹αž›αŸαžΒ αŸ”

αžœαž·αž‘αŸ’αž™αžΆαžŸαžΆαžŸαŸ’αžαŸ’αžšβ€‹ αŸ– αž”αž„αŸ’αž αžΆαž‰β€‹αž›αŸαžβ€‹αž€αŸ’αž“αž»αž„β€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αžœαž·αž‘αŸ’αž™αžΆαžŸαžΆαžŸαŸ’αžαŸ’αžš (αž§αž‘αžΆαž αžšαžŽαŸ 1,00E+03 αžŸαž˜αŸ’αžšαžΆαž”αŸ‹ 1000)Β αŸ”

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.

You can set the locale used for controlling the formatting numbers, dates and currencies in LibreOffice Basic in - Languages and Locales - General. In Basic format codes, the decimal point (.) is always used as placeholder for the decimal separator defined in your locale and will be replaced by the corresponding character.

αž’αž“αž»αžœαžαŸ’αžβ€‹αžŠαžΌαž…β€‹αž‚αŸ’αž“αžΆβ€‹αž‘αŸ…β€‹αž“αžΉαž„β€‹αž€αžΆαžšβ€‹αž€αŸ†αžŽαžαŸ‹β€‹αž˜αžΌαž›αžŠαŸ’αž‹αžΆαž“ αžŸαž˜αŸ’αžšαžΆαž”αŸ‹β€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™β€‹αž€αžΆαž›β€‹αž”αžšαž·αž…αŸ’αž†αŸαž‘ αž–αŸαž›β€‹αžœαŸαž›αžΆ αž“αž·αž„β€‹αžšαžΌαž”αž·αž™αž”αŸαžŽαŸ’αžŽΒ αŸ” αž€αžΌαžŠβ€‹αž‘αŸ’αžšαž„αŸ‹αž‘αŸ’αžšαžΆαž™ Basic αž“αžΉαž„β€‹αžαŸ’αžšαžΌαžœβ€‹αž”αžΆαž“β€‹αž”αž€αž”αŸ’αžšαŸ‚ αž“αž·αž„β€‹αž”αž„αŸ’αž αžΆαž‰β€‹αž‘αŸ…β€‹αžαžΆαž˜β€‹αž€αžΆαžšβ€‹αž€αŸ†αžŽαžαŸ‹β€‹β€‹αž˜αžΌαž›αžŠαŸ’αž‹αžΆαž“β€‹β€‹αžšαž”αžŸαŸ‹β€‹β€‹αž’αŸ’αž“αž€Β αŸ”

Error codes:

5 αž€αžΆαžšβ€‹αž αŸ…β€‹αž”αŸ‚αž”αž”αž‘β€‹αž˜αž·αž“β€‹αžαŸ’αžšαžΉαž˜αžαŸ’αžšαžΌαžœ

Example:


Sub ExampleFormat
    MsgBox Format(6328.2, "##,##0.00")
    REM αžαŸ‚αž„αžαŸ‚β€‹αž”αŸ’αžšαžΎβ€‹αžŸαž‰αŸ’αž‰αžΆ(.) αž‡αžΆβ€‹αž’αžΆαžαž»β€‹αžαžŽαŸ’αžŒβ€‹αž…αŸ‚αž€β€‹ αž“αŸ…αž–αŸαž›β€‹αž’αŸ’αž“αž€β€‹αž”αž‰αŸ’αž…αžΌαž›β€‹αž›αŸαžβ€‹αž€αŸ’αž“αž»αž„β€‹αž€αžΌαžŠβ€‹αž”αŸ’αžšαž—αž–β€‹αž˜αžΌαž›αžŠαŸ’αž‹αžΆαž“Β αŸ”
    REM αž”αž„αŸ’αž αžΆαž‰β€‹ αžŸαž˜αŸ’αžšαžΆαž”αŸ‹β€‹β€‹ 6,328.20 αž€αŸ’αž“αž»αž„β€‹ English locale, 6.328,20 αž€αŸ’αž“αž»αž„ German locale
End Sub

Please support us!