Skip to main content
Skip table of contents

setNumberParser

Creates a parser that can make Number values out of Strings.

Parsers can be used in the logic with the set command, and in document content with the content logic attribute.

Attributes

name

Required

Value type

EL-evaluated

Yes

String

Yes

Defines a name for the created parser. Other commands can choose to use this parser by referring to it by this name.

locale

Required

Value type

EL-evaluated

No

String

Yes

Specifies a locale for this parser, affecting the formatting rules. The resolved String should be an ISO-639 language code and an ISO-3166 country code, joined by a hyphen or an underscore (eg. "en-US" or "en_US"). Alternatively the value may only specify the language code, but this may lead to unpredictable results if this parser requires the country information.

If not defined, the parser will follow the user's default locale.

pattern

Required

Value type

EL-evaluated

No

String

No

The value of this attribute is used as the pattern this parser uses to read Strings and form them into Number values.

If not defined, a locale-dependent standard pattern will be used.

decimalSeparator

Required

Value type

EL-evaluated

No

String

Yes

Defines the symbol that this parser interprets as the decimal separator.

If not defined, a locale-dependent decimal separator is used.

groupingSeparator

Required

Value type

EL-evaluated

No

String

Yes

Defines the symbol that this parser interprets as the grouping separator.

If not defined, a locale-dependent default grouping separator is used.

Examples

Parsing a simple integer-representing String like "1200" into a proper Number is easy enough, a pattern of only #-characters being enough:

CODE
<setNumberParser name="basicParser" pattern="##########">

Parsing of decimal values properly requires not only a pattern recognizing them, but the parser also needs to correctly interpret the decimal separator used. If the number String is "1200.2534", the following two parsers produce different results:

CODE
<setNumberParser name="dotSeparator" pattern="######.####" decimalSeparator="."><setNumberParser name="commaSeparator" pattern="######.####" decimalSeparator=",">

The "dotSeparator" would parse the String into a Number with value 1200.2534, while the "commaSeparator", not being able to interpret the decimal separator, would produce a Number with value 1200.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.