Weight With One Decimal
medium
Prints a weight with exactly one decimal place, '12.4' and not '12.3999996'.
What it teaches
A REAL holds most decimals only approximately: 12.4 is stored as 12.3999996185…, and RTOS prints it as '12.3999996'. Cutting that text after one decimal gives '12.3', because cutting never rounds. Storing a REAL in a DINT does round it, to the nearest whole number. Counted in tenths, 12.4 is the whole number 124, and with a point before its last digit it reads '12.4'. A weight below 1 has a single digit in tenths, 5 for 0.5, so it needs a 0 in front, as the serial number did in Serial Number Text, or it reads '.5'.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Weight | Input | REAL | 12.4 | The weight in kg, 0.0 to 9999.9 |
| Ref_Text | InOut | STRING | — | The weight as the ticket prints it |
Required behavior
- Every scan, Ref_Text is In_Weight rounded to one decimal place, written with a point and one digit after it: 12.4 is '12.4' and 100.0 is '100.0'.
- A weight below 1 has a 0 before the point: 0.5 is '0.5'.
- A REAL cannot hold 12.4 exactly. It holds 12.3999996185…, and RTOS prints '12.3999996', so work with a whole number of tenths and put the point in.
- In_Weight is always 0.0 to 9999.9.
- With the default In_Weight of 12.4, Ref_Text is '12.4'.