Functions for formatting numeric data
Several format functions are available in the JavaScript engine.
Date format
You can format dates 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
You can format currency amount 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 is used to format the amount.
Results in:
$10,987,236.99
Decimal formatting
You can format numbers 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 enables the use of a placeholder. You can replace the placeholder with a value that is retrieved from a query. This format function 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 removes the leading zeroes and move the negative sign to the front.
Example: number = 0000000000500.00-
-
Expression:
number = format.converTrailingSign(number)Results in:
500