A number
type variable holds a numeric value in literal forms such as 255
or 3.14159
.
To create a widget that performs a simple postback, you would write something like this:
In the example above, we created a simple text field that outputs the value of @NumberProperty
. This example is culture-independent, and the WEM runtime checks the culture settings of the portal, using the appropriate number format for validation. For instance, if you set the culture settings to Dutch, the number will be formatted as 200.000,00
. The WEM runtime will use that format for output and validation.
However, this can lead to issues in other contexts, such as JavaScript, where numbers are written in an invariant culture format like 200000.00
. We will discuss this further shortly.
If you have a number that requires exact precision, you can easily achieve this with the precision
option:
There are cases where you may want to work with an invariant culture, especially in JavaScript. This can be accomplished by adding the invariant culture
option. This way, the WEM runtime knows to expect number values that are posted back in the format 200000.00
(using the dot as the decimal separator), making it easier to work with in JavaScript.
However, note that encoding with <?=
, <?attr
, and <?raw
will still output according to the current culture settings, ignoring the invariant culture setting. To clarify: The invariant culture
option is only for postback, so the WEM runtime knows to expect a number value in that format.
The table below provides an overview of the results of different kinds of encoding when outputting a variable declared with var @n: number
, which holds the value 123.45
.
<?= @n ?>
123.45
123,45
123,45
<?attr @n ?>
123.45
123,45
123,45
<?js @n ?>
123.45
123.45
123,45
<?raw @n ?>
123.45
123,45
123,45
When you have a widget number property @NumberProperty
, which you register with register input
, and you want to perform a postback with the value 123.45
, the format you need to use will depend on the culture settings:
123.45
123,45
123,45
123.45