1

I put in my influxDB this Point in java:

            dbConnector.write(Point.measurement(machineData.getOpcuaObject())
                .time(machineData.getTimestamp(), TimeUnit.MILLISECONDS)
                .addField("value2", round(machineData.getValue().floatValue(),2))
                .tag("sensor", machineData.getSensor())
                .build());

But this dont solve the Problem, i dont know why.

if i write into influx so:

.addField("value2", round(machineData.getValue().floatValue(),2))

i became this:

1526622038902000000 0.13704816468572244048 Istdrehm 

if i write into influx so:

.addField("value2", 0.13)

i became this:

 1526622038902000000 0.13 Istdrehm 

Why, any idea?

code of round:

public static float round(float value, int decimalPlace) {
BigDecimal bd = new BigDecimal(Float.toString(value));
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.floatValue();

}

ofitz
  • 152
  • 1
  • 2
  • 14
  • Sounds like you need to debug the Java end of things -- to get the Rounding method correct -- and then the InfluxDB end will work just fine. – Davidgs May 29 '18 at 12:56

1 Answers1

0

This is actually more of a Java question than an InfluxDB question, but since I do both, I thought I'd give an answer. Basically you want to round the number to the nearest 2 decimal places before you store it in InfluxDB, since InfluxDB retains all precision.

see this answer: What's the best practice to round a float to 2 decimals?

for how to round your decimal to 2 significant places before storing that number in InfluxDB.

HTH, dg

Davidgs
  • 411
  • 6
  • 18
  • 1
    thx davidgs i tried it out, but this dont solve the problem. i edit my question with the new code – ofitz May 28 '18 at 06:28