OpenWGA 7.7 - TMLScript reference
WGAMethod :
parseNumber(number, format [,language])
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. |
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): |
Return value |
A Number object containing the parsed numeric value |
Allowed in script types |
|
Examples |
This example creates a Number object containing 1234: var aNumber = WGA.parseNumber("1,234.0", "#,##0.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.0"); |