FmtStr$ Function
Formats a numeric expression or date/time expression.
Syntax
FmtStr$ (expFormat, strFormat)
Parameters
- expFormat
- Specify the numeric or date/time expression to be formatted.
Specify date/time expression in “yyyy/mm/dd”. - strFormat
- Specify the format specification string.
Return Values
A string containing the formatted expression.
Description
Returns the formatted string according to the strFormat.
Numeric Format Specifiers
- None
- Displays the number with no formatting.
- (0)
- Digit placeholder. Display a digit or a zero. If the expression has a digit in the position where “0” appears in the format string, display it; otherwise, display a zero in that position. If the number has fewer digits than there are “0” (on either side of the decimal) in the format expression, display leading or trailing “0”. If the number has more digits to the right of the decimal separator than there are “0” to the right of the decimal separator in the format expression, round the number to as many decimal places as there are “0”. If the number has more digits to the left of the decimal separator than there are “0” to the left of the decimal separator in the format expression, display the extra digits without modification.
- (#)
- Digit placeholder. Display a digit or nothing. If the expression has a digit in the position where “#” appears in the format string, display it; otherwise, display nothing in that position. This symbol works like the 0 digit placeholder, except that leading and trailing “0” aren't displayed if the number has the same or fewer digits than there are “#” characters on either side of the decimal separator in the format expression.
- (.)
- Decimal placeholder. The decimal placeholder determines how many digits are displayed to the left and right of the decimal separator. In some locales, a comma is used as the decimal separator. If the format expression contains only number signs to the left of this symbol, numbers smaller than 1 begin with a decimal separator. To display a leading zero displayed with fractional numbers, use “0” as the first digit placeholder to the left of the decimal separator. The actual character used as a decimal placeholder in the formatted output depends on the Number Format recognized by your system.
- (,)
- A thousand-digit delimiter that separates numeric values by thousands. In some locales, a period is used as a thousand separator. The thousand separator separates thousands from hundreds within a number that has four or more places to the left of the decimal separator. Standard use of the thousand separator is specified if the format contains a thousand separator surrounded by digit placeholders (0 or #). Two adjacent thousand separators or a thousand separator immediately to the left of the decimal separator (whether or not a decimal is specified) means "scale the number by dividing it by 1000, rounding as needed." For example, you can use the format string "##0,," to represent 100 million as “100”. Numbers smaller than 1 million are displayed as “0”. Two adjacent thousand separators in any position other than immediately to the left of the decimal separator are treated simply as specifying the use of a thousand separator. The actual character used as the thousand separator in the formatted output depends on the Number Format recognized by your system.
Date/Time Expression Specifiers
- (:)
- Time separator. In some locals, other characters may be used. The time separator separates hours, minutes, and seconds when time values are formatted. The actual character used as the time separator in the formatted output depends on the Windows settings.
- (/)
- Date separator. In some locals, other characters may be used. The date separator separates day, month, and year when date values are formatted. The actual character used as the date separator in the formatted output depends on the Windows settings.
- c
- Displays the date in “ddddd” and time in “ttttt”, in this order. If the date serial number does not have a fraction, it only displays the date. If the timing information does not have the integer, it only displays the timing information.
- d
- Displays the date with the day in the lead without “0”. (1 to 31)
- dd
- Displays the date with the day in the lead with “0”. (01 to 31)
- ddd
- Displays the abbreviation of the day of the week. (Sun to Sat)
- dddd
- Displays the unabbreviated day of the week. (Sunday to Saturday)
- ddddd
- Displays the day, month, and year in the format of the short data display settings of the Windows. Default setting of the short data display format is m/d/yy.
- dddddd
- Displays the serial values of the date as day, month, and year in the long data display setting of the Windows. Default setting of the long data display is mmmm dd, yyyy.
- w
- Displays the day of the week with a number. (1: Sunday - 7: Saturday)
- ww
- Displays the number of weeks in a year with a number (1 to 54)
- m
- Displays the month without “0” at the beginning. (1 to 12)
Even if this character is placed right after “h” or “hh”, this does not display “minute”. To display “minute”, use “n” or “nn”. - mm
- Displays the month with “0” at the beginning. (01 to 12)
Even if this character is placed right after “h” or “hh”, this does not display “minute”. To display “minute”, use “n” or “nn”. - mmm
- Displays the abbreviated month name. (Jan to Dec)
- mmmm
- Displays the unabbreviated month name. (January to December)
- q
- Displays the number of quarters in a year. (1 to 4)
- y
- Displays the day of a year. (1 to 366)
- yy
- Displays the year in 2 digits. (00 to 99)
- yyyy
- Displays the year in 4 digits. (100 to 9999)
- h
- Displays the time in 24-hour clock without “0” at the beginning. (0 to 23)
- hh
- Displays the time in 24-hour clock with “0” at the beginning. (00 to 23)
- n
- Displays the minute without “0” at the beginning. (0 to 59)
- nn
- Displays the minute with “0” at the beginning. (00 to 59)
- s
- Displays the second without “0” at the beginning. (0 to 59)
- ss
- Displays the second with “0” at the beginning. (00 to 59)
- ttttt
- Displays the time (hour, minute, second) with the time separator of Windows setting. If the “initial zero” option is used, the time before 10:00am/pm are displayed with “0” at the beginning. Default time format of the Windows is h:nn:ss.
- AM/PM
- Displays the time in 12-hour clock and displays morning and afternoon with AM/PM (uppercase).
- am/pm
- Displays the time in 12-hour clock and displays morning and afternoon with am/pm (lowercase).
- A/P
- Displays the time in 12-hour clock and displays morning and afternoon with A/P (uppercase).
- a/p
- Displays the time in 12-hour clock and displays morning and afternoon with a/p (lowercase).
- AMPM
- Displays the time in 12-hour clock. For the morning, displays AM with a string and for the afternoon, displays the PM with a string each with the Windows format setting. Both uppercases and lowercases can be used for AM/PM if the specified string matches the Windows setting. Default Windows setting is AM/PM.
Note
Mixture of numeric format specifiers and time/date specifiers
An error occurs if both numeric format specifier and time/date specifier are specified.
See Also
Left$, Right$, Str$
FmtStr$ Statement Example
Function SendDateCode
String d$, f$
f$ = FmtStr$(10, "000.00")
OpenCom #1
Print #1, f$
CloseCom #1
Fend