# Format$

String = Format$ ( Expression [ , Format ] )

Converts an expression to a string by using a format that depends on the type of the expression. Format can be a predefined format (an integer constant) or a user-defined format (a string that depicts the format).

This function uses localization information to format dates, times and numbers.

See Predefined constants for a list of predefined formats. If Format is not specified, gb.Standard is used.

A user-defined number format is described by the following characters :

- "+" prints the sign of the number.
- "-" prints the sign of the number only if it is negative.
- "#" prints a digit only if necessary.
- "0" always prints a digit, padding with a zero if necessary.
- "." prints the decimal separator.
- "%" multiplies the number by 100 and prints a per-cent sign.
- "E" introduces the exponential part of a float number. The sign of the exponent is always printed.

A user-defined date format is described by the following characters :

- "yy" prints the year on two digits.
- "yyyy" prints the year on four digits.
- "m" prints the month.
- "mm" prints the month on two digits.
- "mmm" prints the month in an abbreviatted string form.
- "mmmm" prints the month in its full string form.
- "d" prints the day.
- "dd" prints the day on two digits.
- "ddd" prints the week day in an abbreviated form.
- "dddd" prints the week day in its full form.
- "/" prints the date separator.
- "h" prints the hour.
- "hh" prints the hour on two digits.
- "n" prints the minutes.
- "nn" prints the minutes on two digits.
- "s" prints the seconds.
- "ss" prints the seconds on two digits.
- ":" prints the time separator.

User-defined numeric format examples:

    PRINT Format$(Pi, "-#.###")

    3.142

    PRINT Format$(Pi, "+0#.###0")

    +03.1416

    PRINT Format$(Pi / 10, "###.# %")

    31.4 %

    PRINT Format$(-11 ^ 11, "#.##E##")

    -2.85E+11

User-defined date and time format examples:

    PRINT Format$(Now, "mm/dd/yyyy hh:nn:ss")

    04/15/2002 09:05:36

    PRINT Format$(Now, "m/d/yy h:n:s")

    4/15/02 9:5:36

    PRINT Format$(Now, "ddd dd mmm yyyy")

    Mon Apr 15 2002

    PRINT Format$(Now, "dddd dd mmmm yyyy")

    Monday April 15 2002

See also Str$, Val

Previous: FOR Next: Frac