Functions for formatting numeric data

Several format functions are available in the JavaScript engine.

Date format

Dates can be formatted based on supplied pattern and locale.

Examples:

  • Expression: dateString = new Date();

    Results in: Mon Aug 05 2013 10:04:33 GMT-0500 (CDT)

  • Expression: dateString = format.formatDate(dateString, "yyyy/MM/dd/HH:mm:ss")

    Results in: 2013/08/05/10:04:12

  • Expression: dateString = format.formatDateWithLocale(dateString, "yyyy.MM.dd G 'at' HH:mm:ss z", "fr")

    Results in: 2013.08.05 ap. J.-C. at 10:04:12 CDT

Currency format

Currency amount can be formatted based on locale.

Examples: amount=10987236.99

  • Expression: amount = format.formatCurrencyWithLocale (amount, "fr")

    Results in: 10 987 236,99 ยค

  • Expression: amount = format.formatCurrency(amount)

    In this example, the default system locale will be used to format the amount.

    Results in: $10,987,236.99

Decimal formatting

Numbers can be formatted based on pattern and locale.

Examples: number=10987236.99

  • Expression: number = format.formatDecimalWithLocale (number, "###,###.###", "fr")

    Results in: 10 987 236,99

  • Expression: number = format.formatDecimal(number, "###,###.###")

    Results in: 10,987,236.99

String format

If dynamic values need to be inserted into a sentence, this option allows the use of a placeholder. The placeholder can be replaced with a value that is retrieved from a query. This format function also makes use of locale to do locale specific formatting.

Examples:

  • Expression: format.formatString("Joe", "Hello %s, how are you?")

    Results in: hello Joe, how are you

  • Expression: format.formatStringWithLocale ("Joe", "hello %s, how are you?", "fr")

COBOL style numbers

If a number has COBOL style formatting with zero padding in front and the negative sign is placed at the end, this formatting function will remove the leading zeroes and move the negative sign to the front.

Example: number = 0000000000500.00-

  • Expression: number = format.converTrailingSign(number)

    Results in: 500