Skip to content

TOI, TOD, TOR, TOS — Convert

Category
Move / Logical
Type
Output
Availability
All platforms

TOS and TOI instruction blocks side by side: TOS Source Flow_Rate, Dest Flow_Txt; TOI Source Flow_Txt, Dest Flow_Int


The four convert instructions change a value’s data type and write the result to Dest every scan the rung is true. There is one instruction per target type: TOI (To INT), TOD (To DINT), TOR (To REAL) and TOS (To STRING). The source type is read from the operand, so a single instruction parses text or casts a number as needed. They are output instructions with no state and no status bits. Use them to turn a reading into text for a display or a message, to parse a number typed into a STRING, or to move a REAL into a DINT without the silent truncation a MOV would hide in plain sight. Do not use them between numeric types when a MOV already does what you want; MOV converts numbers freely, and the converts earn their place at the boundary with text.

Mnemonic Dest type Text Source Numeric Source
TOI INT Leading whole number is parsed ("42 apples" gives 42, "abc" gives 0) Truncated toward zero; wraps past ±32767
TOD DINT Same parse Truncated toward zero; wraps past ±2,147,483,647
TOR REAL Leading decimal number is parsed ("3.14bar" gives 3.14) Exact for an INT; a DINT keeps about seven digits
TOS STRING Copied, cut at 15 characters A whole number prints plain (1450); a REAL prints with four decimals (37.5000)

Operand Type Format Valid Range Required Description
Source Any atomic tag, member, element or bit, or a literal Tag, Tag.Member, Tag[n], Tag.bit, a number, or a quoted string Any resolvable reference Yes The value to convert.
Dest A writable tag, member or element of the target type Tag, Tag.Member, Tag[n] Must match the instruction: INT for TOI, DINT for TOD, REAL for TOR, STRING for TOS Yes Where the converted value is written.

A Dest of the wrong type is a validation error, so the instruction tells you at compile time rather than truncating quietly. A STRING holds 15 characters; a longer result is cut.


Nothing. Dest keeps its power-up value.

The instruction does nothing. Dest holds its last value.

Source is read, converted, and written to Dest every scan the rung is true. Text that does not start with a number converts to 0; nothing faults.

Nothing.


Scenario: A flow reading is turned into text for a serial display, and the same text is parsed back to a whole number to show what a display-side parser would receive. Two blocks on one rung, TOS then TOI, so both results appear in one scan.

Tags:

  • Convert — Run the conversions, BOOL
  • Flow_Rate — Flow in litres per minute, REAL
  • Flow_Txt — The reading as text, STRING
  • Flow_Int — The text parsed back, INT

Rung 1:

—] [Convert———[TOS Flow_Rate Flow_Txt]———[TOI Flow_Txt Flow_Int]———

Scan 1 — Convert = 0. Flow_Rate reads 37.5. The rung is false: Flow_Txt is empty and Flow_Int holds 0. An empty STRING paints as a bare < on the block, with nothing before it.

Figure 1 — TOS and TOI rung false: Flow_Rate 37.5, Flow_Txt empty, Flow_Int 0, rung dark

Scan 2 — Convert = 1. TOS writes 37.5000, four decimals because the source is a REAL. TOI then reads that text on the same scan and writes 37: the parse stops at the decimal point.

Figure 2 — TOS and TOI rung true: Flow_Txt 37.5000, Flow_Int 37, rung lit

Replace the TOI with a TOR into a REAL and the text parses back to 37.5.


  • MOV — Move (number to number, text to text)
  • CPT — Compute (TRN truncates inside an expression)
  • MSG — Message (where converted text usually goes)
  • Move/Logical Instructions — Category index

Four decimals always. TOS on a REAL prints four places whatever the value: 12 becomes 12.0000. Convert through an INT first when a whole number is wanted as text.

Parsing is forgiving. Leading spaces and a sign are accepted; the first character that is not part of a number ends the parse. "12,5" gives 12, not 12.5.

Sixteen-bit limit. TOI of 40000 wraps to −25536 with no warning. Use TOD when the value can exceed 32767.

The block never colours. Watch the rung wire and the Dest value line.

Applies to LadderIDE >=1.2.2 · Last reviewed 2026-09-11 · Screenshots verified 2026-09-11