A screen shows a PLC length as a fraction when the PLC rounds the value to 1/16 or 1/32 steps with integer math and sends a whole-inch count and a numerator as separate fields, with the denominator as fixed text: steps = (hundredths × D + 50) / 100, whole = steps / D, remainder = steps mod D.
A screen can show a PLC length as a fraction, and the conversion belongs in the PLC. Take the length the program already holds, round it to the nearest 1/16 in or 1/32 in step with integer math, split the result into whole inches and a numerator, and send those parts to the screen as separate fields or as one assembled string. Three register operations do it: steps = (hundredths × D + 50) / 100, whole = steps / D and remainder = steps mod D, with D at 16 or 32. No lookup table is involved and the display needs no fraction format. The sections below cover the math, a worked example at 12.37 in, the steps to load it, and the test values that prove the rounding.
What you need
- The length tag and its scale. The math assumes integer hundredths: a tag value of 1237 means 12.37 in. Confirm the scale by running a known length and reading the tag before you build anything.
- A denominator D: 16 for display in sixteenths, 32 for thirty-seconds.
- Display fields: a 2-digit numeric field for whole inches, a numeric field for the numerator, and a fixed text label that reads /16 or /32. A screen that offers a string display takes one text field instead.
- Two or three spare registers for steps, whole and remainder.
Round the length to fraction steps
The tag lives on a 0.01 in grid. A 1/16 in step is 0.0625 in, so the conversion rounds, and the displayed length can sit up to half a step from the true value: 0.03125 in at D = 16, 0.015625 in at D = 32. Round to the nearest step with:
steps = (hundredths × D + 50) / 100
Use integer division. The +50 is half of the 100 in the divisor, so anything within half a step lands on the nearest step. This is scaled-integer math, the same approach as PLC integer math when the CPU has no floating point.
Split the steps into whole inches and a numerator
Two more operations:
whole = steps / D with integer division
remainder = steps mod D
The division handles the carry: a length that rounds past a whole inch lands in the next whole count, so the screen never shows 9-16/16. A remainder of 0 means a whole inch, so blank the numerator or show 0, one rule applied everywhere. If your instruction set has no MOD, compute the remainder as steps - (whole × D); computing a MOD remainder without a MOD instruction shows the working. If the tag can go negative, run the math on the magnitude and reapply the sign, or clamp the tag at 0, and test that path; how a division remainder behaves for negative values shows where a plain MOD goes wrong.
Show the parts on the screen
A numeric display object presents a number and a string field presents characters, so map whole to the whole-inch field, remainder to the numerator field and leave the denominator as fixed text. Give the whole-inch field 2 digits, which covers 0 to 99 in, and the numerator 2 digits, which covers every remainder from 0 to 15 at D = 16 and 0 to 31 at D = 32. Set the zero behavior on purpose: leading zeros on a split HMI numeric display explains what a split display does with them and how to keep or drop them. A fixed denominator keeps every reading on the same grid; reduce 6/16 to 3/8 only if your operators expect textbook fractions, and the halving rule is in the FAQ below.
Worked example: 12.37 in at 1/16
The tag holds 1237 hundredths.
steps = (1237 × 16 + 50) / 100 = 19842 / 100 = 198, dropping the 0.42 with integer division.
whole = 198 / 16 = 12.
remainder = 198 mod 16 = 6, because 198 - (12 × 16) = 6.
The screen shows 12-6/16 in. The true length is 12.37 in and 6/16 is 0.375 in, so the display sits 0.005 in long. The same length at D = 32: steps = (1237 × 32 + 50) / 100 = 39634 / 100 = 396, whole = 12, remainder = 396 - 384 = 12, so 12-12/32 in, the same 12.375 in on a finer grid. A carry case: 9.98 in gives steps = (998 × 16 + 50) / 100 = 16018 / 100 = 160, whole = 10 and remainder = 0, so the screen shows 10 with a blank numerator.
Load the conversion
- Back up the running PLC program and the screen project before any edit.
- Confirm the tag scale with a known length: a 12.37 in part should read 1237.
- Enter the step calculation with integer division: steps = (hundredths × D + 50) / 100.
- Split it: whole = steps / D, remainder = steps mod D or steps - (whole × D).
- Map whole and remainder to the display fields, set the denominator text to /16 or /32, set the 2-digit widths and pick the numerator zero rule.
- For a string display, assemble the text in the PLC, for example 12-6/16, and map one string tag.
- Keep the old decimal readout on the page for now; a numeric display scaled to two decimals does that job, the same scaling described in showing decimal values on an HMI numeric display. Download and run the test values below.
Test values that prove the rounding
Run these five through the real program and compare the screen against the table. A steel rule marked in 1/16 in checks the physical display at the same time.
| Input (in) | steps at D = 16 | Screen shows | What it proves |
|---|---|---|---|
| 0.03 | (3 × 16 + 50) / 100 = 0 | 0, numerator blank | rounds down below the half-step at 0.03125 in |
| 0.04 | (4 × 16 + 50) / 100 = 1 | 0-1/16 | rounds up just past the half-step |
| 0.50 | (50 × 16 + 50) / 100 = 8 | 0-8/16 | an exact half inch stays exact |
| 9.98 | (998 × 16 + 50) / 100 = 160 | 10, numerator blank | carry into the whole inch |
| 12.37 | (1237 × 16 + 50) / 100 = 198 | 12-6/16 | the worked case |
Watch the screen while each value runs: fields lined up, no stray leading zeros, numerator blank when the remainder is 0, and the decimal readout matching until you take it off.
When operators also key lengths in 1/32 in steps, the display math here is the mirror of that entry problem; entering 32nds of an inch on a numeric entry keypad covers the traps on that side.
Recommendation: Do the rounding in the PLC with D = 16 and three separate fields, and keep the decimal readout on the page until all five test values pass. Move to D = 32 only when the process genuinely works to 1/32 in; it cuts the worst display error from 0.03125 in to 0.015625 in. Use one string field when the screen offers one, and settle the negative-value path before the fraction goes live.
Questions
What changes if the PLC stores the length as a REAL?
Round in floating point first: steps = ROUND(length in inches × D). Watch two things. A REAL can hold 12.37 as 12.369999, which still gives 198 steps at D = 16 but can flip a value sitting exactly on a boundary. And some processors round a .5 result up while others round to even. If a boundary case matters, scale the REAL to integer hundredths first and use the body formula.
How do I show 3/8 instead of 6/16?
Reduction is a separate step after rounding. With D = 16 or 32 the denominator is a power of two, so halve while both numbers are even: 6/16 becomes 3/8, and 12/32 becomes 6/16 then 3/8. An odd numerator such as 5 stops the process. The halving loop costs a few rungs of logic; the fixed denominator costs none and keeps every reading on the same grid.
How do I size the fields for lengths over 99 in?
Give the whole-inch field a third digit and it covers 0 to 999 in. Keep the numerator at 2 digits, which already covers every remainder for D = 16 and D = 32. Test the carry before going live: 99.97 in gives (9997 × 16 + 50) / 100 = 1600 steps at D = 16, which splits to 100 whole and 0 remainder, so the third digit must show 100 with a blank numerator.
Planning information, not legal or engineering advice. Rules differ by place: check codes and permits with your local authority and your licensed trades.