Troubleshooting
Why a Sparkplug float shows 16 decimals but the historian shows three
Short answer
A Sparkplug B Float metric is a 32-bit IEEE 754 value carrying about 7 significant decimal digits. The 16-decimal string is that binary value widened to a 64-bit double for display, and the historian's 3-decimal tile is formatting — neither proves stored data changed. Compare the declared data type and decoded value at publisher, broker, collector input and historian query before blaming storage.
On this page
Nothing is being rounded in storage. A Sparkplug B metric whose dataType is Float is a 32-bit IEEE 754 value: 24 significant binary bits, about 7.22 decimal digits. The 16-decimal string such as 3.6440000534057617 is that binary value widened to a 64-bit double for printing, and the historian tile showing 3.644 is display formatting. Digit counts prove nothing in either direction. Compare the declared data type and the decoded 32-bit value at the publisher, the broker payload, the collector input and the historian query; when those agree bit for bit, only the displays differ.
What the 16-decimal string actually is #
IEEE 754 single precision gives a value 1 sign bit, 8 exponent bits and 23 stored fraction bits, plus an implicit leading 1, so 24 significant binary bits. Converted to decimal that is 24 × log10 2 ≈ 7.22 digits, and between 6 and 9 significant decimal digits are accurate depending on the value. Sparkplug B serializes every metric with Protocol Buffers and a dataType field: Float is the 4-byte IEEE 754 encoding, Double the 8-byte one. An R4 or Float4 tag is the same 32-bit format.
Most decimal fractions have no exact binary form, and 3.644 is one of them, so the metric stores the nearest representable binary fraction. When a client widens that value to a 64-bit double and prints enough digits to identify the double, out comes 3.6440000534057617. The widening direction loses nothing — every 32-bit value is exactly representable in 64 bits — while narrowing a double to a float can. Every digit after the seventh in that string is the encoding showing through, not resolution the transmitter ever sent.
What each display actually shows #
The birth message printed 3.621 V for Battery 1/Cell Voltage Average at timestamp 1738825877285, and the client showed 3.6440000534057617 at timestamp 1739931062394. The difference is 1,105,185,109 ms, which is 12.8 days: two different measurements, not one value reformatted. Each writer also prints the fewest digits that identify the value in its own type, which is why the birth serialization stopped at three digits while the widened display reached seventeen.
The tile's decimal count moves with the value — three decimals on a 3.644 V reading, five on a 0.20193 MW power limit. A storage rule does not vary per value; formatting does.
| Where you looked | What you saw | Decimal places | What it establishes |
|---|---|---|---|
| Birth message, publisher serializer | 3.621 V | 3 | One snapshot, 12.8 days older, in the publisher's shortest form |
| Client decoding the live metric | 3.6440000534057617 | 16 | The exact 32-bit value widened to double and fully printed |
| Historian tile | 3.644 | 3 | Display formatting; nothing about stored bits |
| Birth message, second tag | 0.20193 MW | 5 | Same: the count tracks the value, not a rule |
Trace the value from publisher to historian query #
The method is the end-to-end discipline of tracing a PLC tag from controller to historian display, applied to the bytes rather than the configuration:
- Subscribe on the broker to the exact topic the collector consumes, with a client that decodes Sparkplug B. No filter script in between — reformatting timestamps or converting types destroys the evidence.
- Record the metric's
dataTypeand the decoded numeric value for a birth message and a live data message from that topic. - At the publisher, note the source tag's declared type and the value at the same instant, and treat the publisher's own display digits as formatting, not fact.
- Match records by tag name and full timestamp in milliseconds, and write down each tool's time zone before calling two rows the same sample.
- Query the historian for the same tag and timestamp and export the raw returned value to a file, never from a screenshot of a tile.
- Write controlled 32-bit values through the same collection path to a scratch tag and read them back. Use a test tag, not production history: reports and aggregates downstream consume whatever you write.
- Compare decoded values and declared types across the four points — never digit counts.
Working 3.644 V through a 32-bit float #
Inputs #
- Client display of the live Sparkplug metric: 3.6440000534057617 V,
dataType Float(the reader's own case). - Historian tile for the same tag: 3.644 V, engineering unit V.
- Format: IEEE 754 binary32, 24 significant bits including the implicit leading 1.
Rule in words #
Normalize the reading to 1.f × 2^e, scale the fraction by 2^23, round to the nearest integer, and read the stored value back as that exact binary fraction.
Arithmetic #
3.644 V lies in [2, 4), so 3.644 = 1.822 × 2^1 and the fraction to encode is 0.822.
0.822 × 2^23 = 0.822 × 8,388,608 = 6,895,435.776, which rounds to 6,895,436.
Stored value = 2 × (1 + 6,895,436 / 8,388,608) = 30,568,088 / 8,388,608 = 3,821,011 / 1,048,576 = 3.64400005340576171875 V, exactly.
One unit in the last place near 3.6 V is 2^(1-23) = 2^-22 ≈ 2.384 × 10^-7 V, so the stored value sits 5.34 × 10^-8 V — about a quarter of an ULP — from 3.644: the nearest float, as it must be. Widened to 64 bits and printed to identify the double, it reads 3.6440000534057617, the exact string the client showed.
Result and decision #
The 17-digit string is fully explained by the encoding; the client neither added nor lost information. A display resolved to 0.001 V at 3.6 V needs 4 significant decimal digits against the 7.22 the format carries, and the format's 2.384 × 10^-7 V step is about 4,000 times finer than that display. Keep the Float dataType. Publish the 8-byte Double only when a signal genuinely resolves past 7 significant decimal digits, and change it at the publisher — where narrowing would occur — not in any display.
Where real precision loss does happen #
Three places, none of them the historian tile:
- Narrowing at the publisher. A tag computed in 64 bits and published as
Floatis chopped to 32 at that moment; that is the only conversion in this path that discards bits. - Integer scaling. An unscaled integer arrives with count resolution and the scaling applied later decides the digits, the failure mode worked through in historian tag scaling for an unscaled PLC integer value.
- Correlation errors. Millisecond truncation or a time-zone offset — one tool in Pacific, another in Eastern — pairs the wrong rows and looks like value drift.
When to call it a historian defect #
Only one finding counts: a payload captured on the collector's own topic that decodes to one 32-bit value, and a historian query for the same tag and full-precision timestamp that returns a different stored value. That pair, message plus query result, is the defect case; take it to the collector vendor with both artifacts. Anything short of it is a display, and displays are changed in their format settings, not in storage. When the payload itself is wrong, the correction belongs at the publishing client rather than the broker — the same rule that governs fixing Sparkplug B device tags on the client, not the broker.
Questions asked
How many decimal digits can a Sparkplug Float metric actually carry?
A 32-bit IEEE 754 float has 24 significant binary bits, which is 24 × log10 2, about 7.22 decimal digits, and between 6 and 9 significant decimal digits are accurate depending on the value. Digits beyond that in any display come from widening the value to a 64-bit double, so never quote them in reports as measured resolution. If the sensor truly resolves past seven significant digits, publish the 8-byte Double dataType.
Is it worth changing this tag to Double to keep the 16 decimals?
No. The long string is the binary approximation of 3.644 made visible, not extra resolution the transmitter sent. A cell-voltage average displayed to 0.001 V at 3.6 V needs 4 significant digits against the 7 the format carries. Switching to Double widens the field in every payload and buys information the sensor never produced.
Why did the birth message print 3.621 while the live payload printed 3.6440000534057617?
A birth message carries each tag's value only at the moment the publisher connects; every later update arrives in data messages. Here the two timestamps sit 1,105,185,109 ms apart, about 12.8 days, so they are different samples, and each tool prints the fewest digits that identify the value in its own type. Match on full millisecond timestamps and time zone before comparing any two displays.
When is the historian actually at fault?
Only when a payload captured on the collector's own topic decodes to one 32-bit value and a query for the same tag and full-precision timestamp returns a different stored value. Capture both artifacts before contacting the vendor, and expect the first questions to be the exact topic and timestamp. A tile showing fewer decimals than another tool proves nothing about storage.