Format (VBScript)

The Format command enables the given numeric variable to be formatted using a template string expression, and returned as a string.

Placeholder Meaning
0 Display a digit or a zero. If there is a digit in the position specified, display it, otherwise display a 0 in that position. Typically, this is used to add leading and trailing zeros.
# Display a digit or a nothing. If there is a digit in the position specified, display it, otherwise display nothing in that position. Typically, this is used to remove leading and trailing zeros.
. Decimal placeholder.
% Percentage placeholder. The expression is multiplied by 100. This placeholder should be inserted in the position where it is to appear in the formatted string.
, Thousands placeholder. You can also use this to scale down large numbers by using multiple commas. e.g. "##00,," would change 100 million as 100, where numbers less than 1 million would become zero.
E- E+ e- e+

Scientific format. If the template includes at least one digit placeholder (0 or #) to the right of the scientific placeholder, the number will be put into scientific format, where 'E' or 'e' is inserted between the number and its exponent. The number of digit placeholders to the right sets the number of digits in the exponent. Using E- or e- will add a minus sign to negative numbers. Using E+ or e- will add a plus or a minus sign to numbers as appropriate.

Examples

x = 12.579
y = Format(x,"00000.00")

would make y = 00012.57

x = 05012.579
y = Format(x,"##,000.00")

would make y = 5,012.57

Syntax

FORMAT ( numeric argument , format string expression )