Format

Format is a built-in scripting function that formats a numerical value and returns it as a string.

Function Group Execution Windows Embedded Thin Client Mobile Access
Format Arithmetic Synchronous Supported Supported Supported Supported

Syntax

  Format(strFlag,numValue,optStrDecimalMark,optStrThousandSep)  
Web Studio Help  function arithmetic format.xml d64316e114 Format
strFlag
A description of how the given numerical value should be formated, according to the syntax %width.precisionFormat, where:
  • width is the minimum number of characters to be returned by the function. If the value to be returned is shorter than this, then it is padded with either blank spaces (“ ”) or zeroes (“0″); see “Examples” below. The value is not truncated even if the result is longer than the specified width. Applicable for formats d, x, X, o, b, f, e, E, g, G, s, c and h.
  • .precision is the number of decimal places for a floating-point number. Applicable for formats f, e, E, g and G.
  • Format is the specific format:
    Format Description
    d Decimal
    x Hexadecimal (alphabetic characters in lowercase)
    X Hexadecimal (alphabetic characters in uppercase)
    o Octal
    b Binary
    f Floating-point
    e Scientific notation (e in lowercase)
    E Scientific notation (E in uppercase)
    g Rounded (e in lowercase, when applicable)
    G Rounded (E in uppercase, when applicable)
    s String (i.e., no change in number)
    c ASCII character (i.e., the numerical value is interpreted as an ASCII character code)
    h Hour (hh:mm:ss)

Alternatively, the format can be set using the syntax ##.###, where the numerical value is rounded to the specified number of decimal places.

numValue
The numerical value to be formatted.
optStrDecimalMark
The character used as the decimal mark, which separates the integer and fractional parts of the numerical value.

This is an optional parameter; if no value is specified, then the default is a period (.). For example: “123.45″

optStrThousandSep
The character used as the thousands separator, which separates the hundreds and thousands digits of the numerical value.

This is an optional parameter; if no value is specified, then the default is a comma (,). For example: “12,345″

Returned value

This function returns a string that contains the formatted numerical value. See “Examples” below.

Notes

Format is similar to the printf function in other programming languages, and it allows most of the same formatting options. However, unlike printf, Format can be used to format only one numerical value at a time.

This function is particularly useful for formatting values to be printed in reports.

Examples

Expression Returned value
Format("%d",12.34) 12
Format("%04d",12.34) 0012
Format("%4d",12.34)   12
Expression Returned value
Format("%x",26) 1a
Format("%04x",26) 001a
Format("%4x",26)   1a
Expression Returned value
Format("%X",26) 1A
Format("%04X",26) 001A
Format("%4X",26)   1A
Expression Returned value
Format("%o",16) 20
Format("%04o",16) 0020
Format("%4o",16)   20
Expression Returned value
Format("%b",2) 10
Format("%4b",2) 0010
Format("%04b",2) 0010
Expression Returned value
Format("%0.1f",12.34) 12.3
Format("%06.1f",12.34) 0012.3
Format("%6.1f",12.34)   12.3
Expression Returned value
Format("%e",12.34) 1.234000e+001
Format("%0.1e",12.34) 1.2e+001
Format("%09.1e",12.34) 01.2e+001
Format("%9.1e",12.34)  1.2e+001
Expression Returned value
Format("%E",12.34) 1.234000E+001
Format("%0.1E",12.34) 1.2E+001
Format("%09.1E",12.34) 01.2E+001
Format("%9.1E",12.34)  1.2E+001
Expression Returned value
Format("%0.1g",12.34) 1e+001
Format("%0.2g",12.34) 12
Format("%0.3g",12.34) 12.3
Format("%05.3g",12.34) 012.3
Format("%5.3g",12.34)  12.3
Expression Returned value
Format("%0.1G",12.34) 1E+001
Format("%0.2G",12.34) 12
Format("%0.3G",12.34) 12.3
Format("%05.3G",12.34) 012.3
Format("%5.3G",12.34)  12.3
Expression Returned value
Format("%s",12.34) 12
Format("%04s",12.34) 0012
Format("%4s",12.34)   12
Expression Returned value
Format("%c",97) a
Format("%4c",97)    a
Format("%04c",97) 000a
Expression Returned value
Format("%h",30) 00:00:30
Format("%h",60) 00:01:00
Format("%h",90) 00:01:30
Format("%h",3600) 01:00:00
Expression Returned value
Format("##.#",26.56789) 26.6
Format("#.##",26.56789) 26.57
Format("##.##",26.56789) 26.57

Format