Skip to main content

Number formatting

Number formatting locale

Since v4.22.1, the gwen.format.locale.number setting can be configured to control which locale is used to format the number strings (default is en-US).

@Number I format <valueRef> from "<source-format>" to "<target-format>" as <name>

Converts the given numeric value to another format and stores the result in the given name in the global scope.

Where

  • <valueRef> is the name of the binding containing the source numeric value

    • Can be the name of any binding that contains or resolves to a numeric value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • <source-format> is the source decimal number format pattern to convert from
  • <target-format> is the target decimal number format pattern to convert to
  • <name> is the name to bind the formatted numeric value to

Example

Given number is "1234"
When @Number I format number from "#" to "$#,##0.00" as dollars
Then dollars should match number format "$#,##0.00"
And dollars should be "$1,234.00"

Since v4.18.1, Gwen also supports ordinal suffixes (1st, 2nd, 3rd, 4th, etc..)

Given number is "22"
When @Number I format number from "#" to "#(st|nd|rd|th)" as ordinal number
Then ordinal number should match number format "#(st|nd|rd|th)"
And ordinal number should be "22nd"

And (converting the other way)

Given ordinal number is "1st"
When @Number I format ordinal number from "#(st|nd|rd|th)" to "00" as leading zero number
Then leading zero should match number format "00"
And leading zero number should be "01"