Format Function

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.

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.

미리 μ§€μ •λœ μ„œμ‹μ„ μ‚¬μš©ν•  경우 μ„œμ‹ 이름을 λ”°μ˜΄ν‘œλ‘œ λ¬Άμ–΄μ•Ό ν•©λ‹ˆλ‹€.

미리 μ§€μ •λœ μ„œμ‹

General Number: 숫자λ₯Ό μž…λ ₯ν•œ λŒ€λ‘œ ν‘œμ‹œν•©λ‹ˆλ‹€.

Currency: 숫자 μ•žμ— λ‹¬λŸ¬ 기호λ₯Ό μ‚½μž…ν•˜κ³  음수λ₯Ό κ΄„ν˜Έλ‘œ λ¬ΆμŠ΅λ‹ˆλ‹€.

Fixed: μ†Œμˆ˜ ꡬ뢄 기호 μ•žμ— μ΅œμ†Œν•œ ν•˜λ‚˜ μ΄μƒμ˜ 숫자λ₯Ό ν‘œμ‹œν•©λ‹ˆλ‹€.

Standard: 숫자λ₯Ό μ²œλ‹¨μœ„ ꡬ뢄 κΈ°ν˜Έμ™€ ν•¨κ»˜ ν‘œμ‹œν•©λ‹ˆλ‹€.

Percent: μˆ«μžμ— 100을 κ³±ν•˜κ³  λ°±λΆ„μœ¨ 기호λ₯Ό μˆ«μžμ— μΆ”κ°€ν•©λ‹ˆλ‹€.

Scientific: 숫자λ₯Ό κ³΅ν•™μš© μ„œμ‹μœΌλ‘œ ν‘œμ‹œν•©λ‹ˆλ‹€(예: 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.

- μ–Έμ–΄ μ„€μ • - μ–Έμ–΄ μ—μ„œ LibreOffice Basicμ—μ„œ 숫자, λ‚ μ§œ, 톡화 μ„œμ‹μ„ μ œμ–΄ν•˜λŠ” 데 μ‚¬μš©λ˜λŠ” λ‘œμΌ€μΌμ„ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€. Basic μ„œμ‹ μ½”λ“œμ—μ„œ μ†Œμˆ˜μ (.)은 항상 μ—¬λŸ¬λΆ„μ˜ λ‘œμΌ€μΌμ— μ •μ˜λœ μ†Œμˆ˜ κ΅¬λΆ„μžλ₯Ό μœ„ν•œ 자리 ν‘œμ‹œμžλ‘œ μ‚¬μš©λ˜μ–΄ ν•΄λ‹Ή 문자둜 λ°”λ€Œκ²Œ λ©λ‹ˆλ‹€.

λ‚ μ§œ, μ‹œκ°„ 및 톡화 μ„œμ‹μ— λŒ€ν•œ ꡭ가별 섀정에도 λ™μΌν•˜κ²Œ μ μš©λ©λ‹ˆλ‹€. Basic μ„œμ‹ μ½”λ“œλŠ” μ‚¬μš©μžμ˜ ꡭ가별 섀정에 따라 ν•΄μ„λ˜μ–΄ ν‘œμ‹œλ©λ‹ˆλ‹€.

Error codes:

5 잘λͺ»λœ ν”„λ‘œμ‹œμ € ν˜ΈμΆœμž…λ‹ˆλ‹€.


Sub ExampleFormat
    MsgBox Format(6328.2, "##,##0.00")
    REM은 μ‚¬μš©μžκ°€ Basic 원본 μ½”λ“œμ— 숫자λ₯Ό μž…λ ₯ν•  λ•Œ 항상 λ§ˆμΉ¨ν‘œλ₯Ό μ†Œμˆ˜ ꡬ뢄 기호둜 μ‚¬μš©ν•©λ‹ˆλ‹€.
    REM displays for example 6,328.20 in English locale, 6.328,20 in German locale.
End Sub

Please support us!