Number Examples
These examples do not require specific object data to produce the defined result.
For function syntax information and more detailed use cases, refer to the Number Functions documentation here.
Copy and paste any of the Value Template text below into the Function Editor, select any object, and click the Evaluate button to display the defined Result.
Value Template |
Result |
---|---|
1.25*11 |
13.75 |
int(5.64) |
5 |
int(-5.64) |
-6 |
text(2.45, '000.0') |
002.5 |
text(2.45, '.0') |
2.5 |
text(2000.45, ',.0') |
2,000.5 |
trunc(5.64) |
5 |
trunc(-5.64) |
-5 |
round(5.64, 0) |
6 |
round(5.64, 1) |
5.6 |
round(5.64, -1) |
10 |
Controlling Decimal Places
These example calculated attributes are written to use a product with the attribute data defined in the following table.
Attribute |
height |
width |
length |
Value |
50.3 cm |
135.26 cm |
75.1 cm |
After creating the data above, copy and paste any of the Value Template text below into the Function Editor, select the object with the defined data, and click the Evaluate button to display the Result.
Value Template |
Result |
Notes |
---|---|---|
(value('length'))*(value('width')) |
10158.026 |
No formatting is applied to the resulting number. |
prodval('height', 'unece.unit.CMT') * prodval('width', 'unece.unit.CMT') * prodval('length', 'unece.unit.CMT') |
510948.7078 |
No formatting is applied to the resulting number. |
text(prodval('height', 'unece.unit.CMT') * prodval('width', 'unece.unit.CMT') * prodval('length', 'unece.unit.CMT'), "000,000.0") |
510,948.7 |
The TEXT function adds a thousands delimiter and reduces the decimal places to 1 |
concatenate(prodvalsimple('height','unece.unit.CMT'), ' H x ', prodvalsimple('width','unece.unit.CMT'),' W x ', prodvalsimple('length','unece.unit.CMT'),' L') |
50.3 cm H x 135.26 cm W x 75.1 cm L |
Static text strings provide a typical display for dimension information.
|
concatenate(trunc(prodval('height')), " x ", trunc(prodval('width')), " x ", trunc(prodval('length'))) |
50 x 135 x 75 |
The TRUNC function eliminates the decimal point and places. |
concatenate(int(prodval('height')), " x ", int(prodval('width')), " x ", int(prodval('length'))) |
50 x 135 x 75 |
The INT function returns the integer part of the number. |
concatenate(round(prodval('height'),1), " x ", round(prodval('width'),0), " x ", round(prodval('length'),-1)) |
50.3 x 136 x 80 |
The ROUND function, using each of the available precision values (1, 0, -1), controls the decimal places for each value being used. |
Localized Number
These example calculated attributes are written to use a product with the attribute data defined in the following table.
Attribute |
Diameter |
Value |
12,7 |
Locale Setting |
'comma-is-decimal' method |
Copy and paste any of the Value Template text below into the Function Editor, select the object with the defined data, and click the Evaluate button to display the Result.
Value Template |
Result |
Notes |
---|---|---|
{x := value('Diameter'), y := 3.414, num_us := localizenumber(x, "en_US"), num_de := localizenumber(x, "de_DE"), p := num_us*y, q := num_de*y, num := localizenumber(p) } concatenate(x, "; ", p, "; ", q, "; ", num) |
12,7; 43.3578; NaN; 43,3578 |
If you attempt to make a math calculation on a number using the comma-is-decimal method, the calculation does not work, as indicated by the NaN ('not a number') result. Instead, perform calculations in a 'dot-is-decimal' locale (en_US or en_GB, for example) and then convert back to the preferred locale after the calculation has been done. In this example, this is done by the statement 'num := localizenumber(p),' which reverts the calculated number to the format according to the locale that is specified in the currently selected context. |