Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

PI SQL Data Access Server (RTQP Engine)

FORMAT with a numeric argument

  • Last UpdatedDec 19, 2022
  • 2 minute read

The FORMAT function formats a number according to the specified format mask.

Syntax

String FORMAT(x Float64, 'mask String')

Arguments

  • x

    A numeric expression to format.

  • mask

    Format-control string. See the following table.

    Note: The FORMAT function also works with a DateTime argument. For more information, see FORMAT with a DateTime argument.

    Mask options

    The format mask may contain one or more of the following characters:

    Character

    Description

    #

    Each instance of the character represents a position for one digit. If no value exists in a position, an empty string is used in that position.

    For example, if you specify a format of #,### and have a value of 45, the function returns the number 45. If you have a value of 12145, the function returns 12,145, even though you defined only one placeholder to the left of the thousands separator.

    0

    Each instance of the character represents a position for one digit. If no value exists in a position, the function displays 0.

    Thousands separators

    Indicates that the thousands separators are used. The location of the separator in the mask does not determine the location of the separator in the result.

    Decimal separator

    Indicates that the decimal separator is used.

    E, E+ , E-, e, e+, or e-

    Represents values in scientific (exponential) notation. Use this option for very large or very small values. You must use these mask characters with other characters.

    The + or - in the mask indicate that a plus or minus sign should always precede the exponent. The sign used is dependent on the actual value being formatted. If you do not use a plus or minus sign in the mask, a plus sign does not appear before the exponent; however, for small values, the negative sign is always included.

    For example, if you specify a format of 0.000E+00 and have a value of 612345, the function returns 6.123E+05. If you specify a format of #.##e## and have a value of 98765, the function returns 9.88e4. If you specify a format of #.##e## and have a value of 0.004567, the function returns 4.57e-3.

    g

    Formats the number using the shortest possible format for the value.

Examples

  • SELECT Format(5459.4, '##,##0.00') - Returns 5,459.40

  • SELECT Format(334.9, '###0.00') - Returns 334.90

  • SELECT Format(5, '0.00') - Returns 5.00

  • SELECT Format(123.456, '##.##') - Returns 123.46

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in