OpenWGA 7.0 - TMLScript reference

WGA
Method :

parseNumber(number, format)

On object WGA
Usage Converts a string containing numeric information into a Number object
Description This method parses the given string based on a custom number format and return it as JavaScript Number object. You must specify the number format that the string contains in parameter "format" using the same syntax described on WebTML attribute format for numeric output.

If the string is unparseable for the given number format the method will throw a JavaScript error wrapping a Java exception of type java.text.ParseException.

Regarding numeric format strings and localisation: OpenWGA uses those characters for decimal and thousands divider that the preferred language of the current user implies. For example: In english speaking countries it is common to use the point "." as decimal divider and the comma "," as thousands divider, while in german speaking countris this usually is vice versa.

However when defining format strings, like in the format parameter of this method, the decimal divider is always represented by the point "." and the thousands divider always by the ",", even if the current locale would use other characters in parsing. This is neccessary so the same format string can be used for different locales and does not need to be redefined for each locale.
For backward compatibility there still is a method "parseNumber()" available on TMLContext whose use is discouraged since OpenWGA 5.3.

Parameters number (String):
String containing a numeric value in a special format

format (String):
String containing the format in which the numeric value is given. See WebTML attribute format for the syntax how to specify it.

language (String, optional):
A language string determining the language for language dependent formattings. Omit to let OpenWGA language behaviour choose the language.

Return value A Number object containing the parsed numeric value
Allowed in script types
  • WebTML pages and normal WebTML actions
  • Master actions
  • TMLScript tasks in jobs
  • Content type events
Examples This example creates a Number object containing 1.234:

var aNumber = WGA.parseNumber("1,234.0", "#,##0.00.0");


When the user has german as preferred language he is likely to use the comma as decimal divider and a point as optional thousands divider. So the following code would work when the preferred language is german, although format string and numeric literal seem to conflict:

var aNumber = WGA.parseNumber("1.234,0", "#,##0.00.0");