Decimal places of input / feed data

My SonoffPow reports the power consumption to 3 decimal places but the inputs (via MQTT) only appear as either 1 or 2 DPs.

Is this configurable? Can I force Emoncms to record the data to a greater accuracy? I’m processing it through Node-Red so I could easily multiply it up there and process it back down in Emoncms, but would the resultant feed round/truncate it?

(2 items below are slightly different times so not the same data)

{
	"Time": "2018-10-12T16:48:30+01:00",
	"ENERGY": {
		"Total": 712.723,
		"Yesterday": 0.003,
		"Today": 0.002,
		"Period": 0,
		"Power": 0,
		"ApparentPower": 0,
		"ReactivePower": 0,
		"Factor": 0.00,
		"Voltage": 239,
		"Current": 0.000
	}
}

image

Hi Brian, “only appear” is right, emoncms and the PHP code uses floats, on most 64bit platforms that is actually a double ie 64bit float. However the emoncms input page doesn’t display the full 64bit float, it rounds (depending on the magnitude of the number I believe) to either 1 or 2 decimal places, but the actual value is usually to 7 significant digits so only when you go above 9999.999 will you actually get less than 3 decimal place accuracy used in the calculations, regardless of what the inputs page displays.

floats are a nightmare!

Even if you post 0.1 to emoncms and see 0.1 on the inputs page it will be using 0.100000000000000005551115123126 in the maths not 0.1. And if you store that 0.1 to a feed it will be stored as 0.100000001490116119384765625 (note this is a different 0.1 to the 64bit PHP as the feeds are 32bit floats :smile:), not that it matters much as that would then be displayed as 0.1 on the feeds page and in graphs etc for the same reason as the inputs page, so it is only really during calculations that any of this could become a problem and hopefully (as long as you only use small numbers and not big meter readings etc) not impact the maths too much.

Great thanks. Could what is to be displayed be configurable? Would this be the same for the feeds page (not created a feed yet).

It’s not user configurable, but you could change locally, I think this might be the code you need to look at.

I also believe this is used for both the input and feed pages, but I could be wrong, I’ve not delved too deep into it myself as it is only the displayed data.

1 Like