Format Function

Formats a numeric expression and returns it as a string.

Format (number, format)

Parameters

Number  -  (Input, expression, Required)

Specifies the number to be formatted.

Format  -  (Input, expression, Required)

Specifies a formatting string, which determines how the number will be converted.

Empty string

Displays the number without any formatting.

0

Digit placeholder.
Used to display leading or trailing zeroes if the number has fewer digits than there are zeroes (to either the left or right of the decimal point). If there are more digits in the number to the left of the decimal point (i.e. integer digits) than there are zeroes in the format string, then these digits will be displayed (i.e. the integer portion will never be truncated). If there are more digits to the right of the decimal point, then the number will be rounded to the nearest place as indicated by the number of zeroes to the right of the decimal place within the format string.

#

Digit placeholder.
Follows the same rules as the 0 character, except that leading or trailing zeroes are not displayed. Note that the resulting string is only large enough to hold the final string and is not padded with spaces for where unused # digits are specified.

.

Decimal placeholder.
Determines the position of the decimal place. Specifying more than one decimal placeholder within the format string will cause the result to be Error. If the format string does not contain any decimal placeholder, any fractional portion of the number will be rounded and the result will contain only integer digits. The actual character used to represent the decimal point in the resulting expression depends on the setting defined within the International section of the Win.ini file (can be modified from the Windows Control Panel). Some countries use a comma as the decimal separator.

,

Thousand separator.
Used to separate thousands for numbers that have 4 or more digits to the left of the decimal point. If the thousands separator is used within # digit placeholders and there are not enough digits in the number to fill them, then the thousands separator does not display either. A thousand separator specified anywhere other than to the left of the decimal placeholder is treated as a literal character and also inserted. The actual character used to represent the thousands separator depends on the setting defined within the International section of the Win.ini file (can be modified from the Windows Control Panel). Some countries use a period as the thousands separator.

%

Percentage placeholder.
Determines the position of the percent sign. The number is multiplied by 100. Specifying more than one percentage placeholder within the format string will cause the result to be Error.

E- E+ e- e+

Scientific notation.
If these characters are used, newlook reformats the number in scientific format and inserts an E or e in between the number and its exponent. The number of digits to the right determines the number of digits to be displayed within the exponent. Use E- or e- to precede the exponent with a minus sign if the exponent is negative. E+ or e+ works the same, except that it will insert a plus sign if the exponent is positive or zero.

\

Literal characters.
Characters proceeded with the backslash (\) character are treated as literal characters which are inserted without interpretation. E.g. You could insert a fixed literal character 0 which will not be used as a digit placeholder by using the \0 character sequence.

“ABC”

String literals.
To guarantee an entire string is included without formatting interpretation, you can enclose it within the double quote character. To insert the double quote character into a string use the Chr(34) function (34 is the ANSI code for the double quote character).

Any others

All other characters (not listed above) are simply inserted one-for-one as literal characters into the final resulting string.

A format expression may have one, two or three sections, each delimited by a semi-colon (;) character. The following explains how the use of each section works:

Return Value

A string containing the formatted number.

Examples

Format (123.456, “”)

Returns “123.456”

Format (123.456, “0”)

Returns “123”

Format (123.456, “0.00”)

Returns “123.46”

Format (123.456, “$#,##0.00;($#,##0.00)”)

Returns “$123.46”

Format (-123456, “$#,##0.00;($#,##0.00)”)

Returns " ($123,456.00)"

Format (123.456, “0%”)

Returns “12346%”

Format (123.456, “0.00e+00”)

Returns “1.23e+02”

TIP:

Functions are specifically for use in the Macro Editor. Refer to Microsoft's official VB and JScript documentation for scripting equivalents.

See Also

Functions | Asc function | Chr function | CSet function | Format function | InStr function | LCase function | Left function | Len function | LSet function | LTrim function | Mid function | Replace function | Right function | RSet function | RTrim function | Space function | String function | TCase function | Trim function | UBound function | UCase function


© 2004-2021 looksoftware. All rights reserved.