1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski
3*b1cdbd2cSJim Jagielski
4*b1cdbd2cSJim Jagielski<!--***********************************************************
5*b1cdbd2cSJim Jagielski *
6*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
7*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
8*b1cdbd2cSJim Jagielski * distributed with this work for additional information
9*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
10*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
11*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
12*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
13*b1cdbd2cSJim Jagielski *
14*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
15*b1cdbd2cSJim Jagielski *
16*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
17*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
18*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
20*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
21*b1cdbd2cSJim Jagielski * under the License.
22*b1cdbd2cSJim Jagielski *
23*b1cdbd2cSJim Jagielski ***********************************************************-->
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski<helpdocument version="1.0">
28*b1cdbd2cSJim Jagielski<meta>
29*b1cdbd2cSJim Jagielski<topic id="textsbasicshared03120301xml" indexer="include" status="PUBLISH">
30*b1cdbd2cSJim Jagielski<title id="tit" xml-lang="en-US">Format Function [Runtime]</title>
31*b1cdbd2cSJim Jagielski<filename>/text/sbasic/shared/03120301.xhp</filename>
32*b1cdbd2cSJim Jagielski</topic>
33*b1cdbd2cSJim Jagielski<history>
34*b1cdbd2cSJim Jagielski<created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
35*b1cdbd2cSJim Jagielski<lastedited date="2004-09-15T10:04:02">converted from old format - fpe</lastedited>
36*b1cdbd2cSJim Jagielski</history>
37*b1cdbd2cSJim Jagielski</meta>
38*b1cdbd2cSJim Jagielski<body>
39*b1cdbd2cSJim Jagielski<section id="format">
40*b1cdbd2cSJim Jagielski<bookmark xml-lang="en-US" branch="index" id="bm_id3153539"><bookmark_value>Format function</bookmark_value>
41*b1cdbd2cSJim Jagielski</bookmark>
42*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3153539" xml-lang="en-US" level="1" l10n="U" oldref="1"><link href="text/sbasic/shared/03120301.xhp" name="Format Function [Runtime]">Format Function [Runtime]</link></paragraph>
43*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3156042" xml-lang="en-US" l10n="U" oldref="2">Converts a number to a string, and then formats it according to the format that you specify.</paragraph>
44*b1cdbd2cSJim Jagielski</section>
45*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3145090" xml-lang="en-US" level="2" l10n="U" oldref="4">Syntax:</paragraph>
46*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153527" xml-lang="en-US" l10n="U" oldref="5">Format (Number [, Format As String])</paragraph>
47*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3149178" xml-lang="en-US" level="2" l10n="U" oldref="6">Return value:</paragraph>
48*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148474" xml-lang="en-US" l10n="U" oldref="7">String</paragraph>
49*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3159176" xml-lang="en-US" level="2" l10n="U" oldref="8">Parameters:</paragraph>
50*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3149415" xml-lang="en-US" l10n="U" oldref="9">
51*b1cdbd2cSJim Jagielski<emph>Number:</emph> Numeric expression that you want to convert to a formatted string.</paragraph>
52*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3147531" xml-lang="en-US" l10n="U" oldref="10">
53*b1cdbd2cSJim Jagielski<emph>Format:</emph> String that specifies the format code for the number. If <emph>Format</emph> is omitted, the Format function works like the <emph>Str</emph> function.</paragraph>
54*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3147561" xml-lang="en-US" level="2" l10n="U" oldref="47">Formatting Codes</paragraph>
55*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3147265" xml-lang="en-US" l10n="U" oldref="11">The following list describes the codes that you can use for formatting a number:</paragraph>
56*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153380" xml-lang="en-US" l10n="U" oldref="12">
57*b1cdbd2cSJim Jagielski<emph>0:</emph> If <emph>Number</emph> has a digit at the position of the 0 in the format code, the digit is displayed, otherwise a zero is displayed.</paragraph>
58*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3151210" xml-lang="en-US" l10n="U" oldref="13">If <emph>Number</emph> 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 number 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.</paragraph>
59*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3151176" xml-lang="en-US" l10n="U" oldref="14">Decimal places in the number are rounded according to the number of zeros that appear after the decimal separator in the <emph>Format </emph>code.</paragraph>
60*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3154123" xml-lang="en-US" l10n="U" oldref="15">
61*b1cdbd2cSJim Jagielski<emph>#:</emph> If <emph>Number</emph> contains a digit at the position of the # placeholder in the <emph>Format</emph> code, the digit is displayed, otherwise nothing is displayed at this position.</paragraph>
62*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148452" xml-lang="en-US" l10n="U" oldref="16">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 number. Only the relevant digits of the number are displayed.</paragraph>
63*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3159150" xml-lang="en-US" l10n="U" oldref="17">
64*b1cdbd2cSJim Jagielski<emph>.:</emph> The decimal placeholder determines the number of decimal places to the left and right of the decimal separator.</paragraph>
65*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3159252" xml-lang="en-US" l10n="U" oldref="18">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.</paragraph>
66*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153368" xml-lang="en-US" l10n="U" oldref="19">
67*b1cdbd2cSJim Jagielski<emph>%:</emph> Multiplies the number by 100 and inserts the percent sign (%) where the number appears in the format code.</paragraph>
68*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3149481" xml-lang="en-US" l10n="U" oldref="20">
69*b1cdbd2cSJim Jagielski<emph>E- E+ e- e+ :</emph> If the format code contains at least one digit placeholder (0 or #) to the right of the symbol E-, E+, e-, or e+, the number 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.</paragraph>
70*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3149262" xml-lang="en-US" l10n="U" oldref="21">If the exponent is negative, a minus sign is displayed directly before an exponent with E-, E+, e-, e+. If the exponent is positive, a plus sign is only displayed before exponents with E+ or e+.</paragraph>
71*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148617" xml-lang="en-US" l10n="U" oldref="23">The thousands delimiter is displayed if the format code contains the delimiter enclosed by digit placeholders (0 or #).</paragraph>
72*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3163713" xml-lang="en-US" l10n="CHG" oldref="29">The use of a period as a thousands and decimal separator is dependent on the regional setting. When you enter a number directly in Basic source code, always use a period as decimal delimiter. The actual character displayed as a decimal separator depends on the number format in your system settings.</paragraph>
73*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3152887" xml-lang="en-US" l10n="U" oldref="24">
74*b1cdbd2cSJim Jagielski<emph>- + $ ( ) space:</emph> A plus (+), minus (-), dollar ($), space, or brackets entered directly in the format code is displayed as a literal character.</paragraph>
75*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148576" xml-lang="en-US" l10n="U" oldref="25">To display characters other than the ones listed here, you must precede it by a backslash (\), or enclose it in quotation marks (" ").</paragraph>
76*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153139" xml-lang="en-US" l10n="U" oldref="26">\ : The backslash displays the next character in the format code.</paragraph>
77*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153366" xml-lang="en-US" l10n="U" oldref="27">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.</paragraph>
78*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3155411" xml-lang="en-US" l10n="U" oldref="28">Characters that must be preceded by a backslash in the format code in order to be displayed as literal characters are date- and time-formatting characters (a, c, d, h, m, n, p, q, s, t, w, y, /, :), numeric-formatting characters (#, 0, %, E, e, comma, period), and string-formatting characters (@, &amp;, &lt;, &gt;, !).</paragraph>
79*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3145749" xml-lang="en-US" l10n="U" oldref="30">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.</paragraph>
80*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3150113" xml-lang="en-US" l10n="U" oldref="31">If you use predefined formats, the name of the format must be enclosed in quotation marks.</paragraph>
81*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3149377" xml-lang="en-US" level="2" l10n="U" oldref="32">Predefined format</paragraph>
82*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3154730" xml-lang="en-US" l10n="U" oldref="33">
83*b1cdbd2cSJim Jagielski<emph>General Number:</emph> Numbers are displayed as entered.</paragraph>
84*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153158" xml-lang="en-US" l10n="U" oldref="34">
85*b1cdbd2cSJim Jagielski<emph>Currency:</emph> Inserts a dollar sign in front of the number and encloses negative numbers in brackets.</paragraph>
86*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3154490" xml-lang="en-US" l10n="U" oldref="35">
87*b1cdbd2cSJim Jagielski<emph>Fixed:</emph> Displays at least one digit in front of the decimal separator.</paragraph>
88*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153415" xml-lang="en-US" l10n="U" oldref="36">
89*b1cdbd2cSJim Jagielski<emph>Standard:</emph> Displays numbers with a thousands separator.</paragraph>
90*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3150715" xml-lang="en-US" l10n="U" oldref="37">
91*b1cdbd2cSJim Jagielski<emph>Percent:</emph> Multiplies the number by 100 and appends a percent sign to the number.</paragraph>
92*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153836" xml-lang="en-US" l10n="U" oldref="38">
93*b1cdbd2cSJim Jagielski<emph>Scientific:</emph> Displays numbers in scientific format (for example, 1.00E+03 for 1000).</paragraph>
94*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3153707" xml-lang="en-US" l10n="U" oldref="39">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.</paragraph>
95*b1cdbd2cSJim Jagielski<embed href="text/sbasic/shared/00000003.xhp#languageformat"/>
96*b1cdbd2cSJim Jagielski<embed href="text/sbasic/shared/00000003.xhp#errorcode"/>
97*b1cdbd2cSJim Jagielski<embed href="text/sbasic/shared/00000003.xhp#err5"/>
98*b1cdbd2cSJim Jagielski<paragraph role="heading" id="hd_id3149019" xml-lang="en-US" level="2" l10n="U" oldref="40">Example:</paragraph>
99*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3156054" xml-lang="en-US" l10n="U" oldref="41">Sub ExampleFormat</paragraph>
100*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3148993" xml-lang="en-US" l10n="U" oldref="42">MsgBox Format(6328.2, "##,##0.00")<comment>Translators: do not change the decimal point in 6328.2, and do not change "##,##0.00" because BASIC uses US notation in all locales.</comment></paragraph>
101*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_idN107A2" xml-lang="en-US" l10n="NEW">REM always use a period as decimal delimiter when you enter numbers in Basic source code.</paragraph>
102*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3147339" xml-lang="en-US" l10n="U" oldref="46">REM displays for example 6,328.20 in English locale, 6.328,20 in German locale.</paragraph>
103*b1cdbd2cSJim Jagielski<paragraph role="paragraph" id="par_id3156382" xml-lang="en-US" l10n="U" oldref="43">End Sub</paragraph>
104*b1cdbd2cSJim Jagielski</body>
105*b1cdbd2cSJim Jagielski</helpdocument>
106