User Tools

Site Tools


k9:k9.2:start

9.2 User-defined formats

Format ( Expression [ , Format ] ) AS String

The Format (..) function converts an expression into a string. You can optionally specify a user-defined format with a format string that depends on the type of expression. The format function can format numbers, currencies, dates and times.

9.2.1 General syntax

A user-defined format is described by a sequence of special characters (character string).
Characters before and after the format string are output as specified.

9.2.2 Format syntax for a numeric expression

+ 	Outputs the sign + the number
- 	Outputs the sign - of the number; but only if the number is negative.
# 	Returns a digit if necessary.

The number is filled with blanks on the left, so that the number of digits before the decimal point is greater than or equal to the number of # before the decimal point.

Examples:

0 	A digit is always output with a leading zero if necessary.
. 	Outputs the decimal separator.
,	Outputs the thousands separator.
%	Multiplies the number by 100 and appends the % sign.
E 	Represents the exponential part of a number. The sign of the exponent is always output.

Examples:

PRINT Format$(Pi, "-#.###")
3.142
PRINT Format$(Pi, "+0#.###0")
+03.1416
PRINT Format$(Pi / 10, "###.# %")
31.4 %
Print Format$(-2.3 ^ 7, "#.####E##")
-3,405E+2

9.2.3 Format syntax for currencies

To format currencies, you can use all numeric format characters and additionally the following:

  • $ Returns the national currency sign.
  • $$ In this case, the international currency sign (short form) is output.
  • ( Symbolizes a negative currency value and must be the first character in the format string. You can specify a closing bracket) at the end of the format string.

Examples:

Print Format$(1234.56, "$$#.##")
1234,56 EUR
Print Format$(-1234.56, "$,#.###")
-1.234,56 €
Print Format$(-1234.56, "($,#.###)")
(1.234,56 €)

9.2.4 Format syntax for date and time values

yy 	Displays the year with the last two digits.
yyyyy 	Returns the year with four digits.
m 	Displays the month.
mm 	Displays the month with two digits.
mmm 	Returns the month in abbreviated localized form.
mmmm 	Displays the month in full localized form.
d 	Displays the day.
dd 	Returns the tag with two digits.
ddd 	Returns the weekday in abbreviated localized form.
dddd 	Returns the month in full localized form.
/ 	Outputs the date separator.
h 	Displays the hours.
hh 	Displays the hours with two digits.
n 	Displays the minutes. "and not m, as one would suspect."
nn 	Returns the minutes with two digits.
s 	Returns the seconds.
ss 	Returns the seconds with two digits.
:  	Displays the time separator.
u 	Returns the milliseconds if they are not zero. As a separator to the seconds, you should be able to insert a dot.
uuuu 	Outputs the milliseconds with three digits.
t 	Specifies the time zone (abbreviation).

Attention:
Every character or string in the syntax overview of date and time formats is interpreted in the format string as specified:

Print "It was "; Format$(Now, "hh:nn o'clock (Uhr)")

It was 09:57 U9r ← Error , because h is a pre-defined sign in the German word 'Uhr'!

Examples:

Print "Today is "; Format$(Now(), "dddd"); ", the "; Format$(Now(), "d. mmmm yyyy")
Print "It was "; Format$(Now, "hh:nn"); " o'clock!"
Print "It was exactly "; Format$(Now, "hh:nn:ss.uuu"); " o'clock!"
Print "Time = "; Format(Now(), "hh:nn:ss"); " o'clock!"  ' Current kitchen time ...
Print "UTC  = "; Format(Time(DateAdd(Now(), gb.second, System.TimeZone)), "hh:nn:ss"); " o'clock"
Print "System.TimeZone = "; System.TimeZone
Print "System.FirstDayOfWeek = "; System.FirstDayOfWeek
Print "It was "; Format$(Now, "hh:nn"); " o'clock"; Format$(Now, " (t)")

Today is Wednesday, June 4,2014
It was 09:40 a. m.
It was exactly 09:40:37:37:404 a.m.
Time = 09:40:37 a.m.
UTC = 08:40:37 a.m.
TimeZone = -3600
System.FirstDayOfWeek = 1
It was 09:40 a.m. (CET)</code>

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k9/k9.2/start.txt · Last modified: 11.02.2022 (external edit)

Page Tools