-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
Describe the bug
Some floating point numbers with two or more zeros after the decimal point only have four or three significant decimal digits.
Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:
[Paste the report here]
- The program uses ArduinoJson 7
- The issue happens at run time
- The issue concerns serialization
- Output is incomplete
JsonDocument::overflowed()
returnsfalse
- The empty/missing value is neither an array, object, nor string
- The output is neither a
char*
,char[N]
,MqttClient
, norPubSubClient
Environment
Here is the environment that I used:
- Microcontroller: ESP32
- Core/runtime: ESP32 core for Arduino v2.0.17 & v3.3.0]
- IDE: 2.3.6
Reproduction
Here is a small snippet that reproduces the issue.
#ifndef ARDUINO_ESP32_DEV
# error - Board mismatch. "ESP32 Dev Module" required.
#endif /* ARDUINO_ESP32_DEV */
#define ARDUINOJSON_USE_DOUBLE 1
#include <ArduinoJson.h>
void setup() {
Serial.begin(115200);
delay(500);
Serial.println();
Serial.println("================================================================================");
Serial.println();
Serial.print("ArduinoJson-Version: ");
Serial.println(ARDUINOJSON_VERSION);
double doubleA = 0.001403982;
double doubleB = 0.001043521;
double doubleC = 0.033841712;
double doubleD = 0.025639649;
double doubleE = 0.000292723;
JsonDocument testDouble;
testDouble["testA"] = doubleA;
testDouble["testB"] = doubleB;
testDouble["testC"] = doubleC;
testDouble["testD"] = doubleD;
testDouble["testE"] = doubleE;
String strTestDouble;
serializeJson(testDouble, strTestDouble);
Serial.println();
Serial.println(strTestDouble);
JsonDocument testJson;
deserializeJson(testJson, strTestDouble);
Serial.println();
Serial.println(testJson["testA"].as<double>(), 9);
Serial.println(testJson["testB"].as<double>(), 9);
Serial.println(testJson["testC"].as<double>(), 9);
Serial.println(testJson["testD"].as<double>(), 9);
Serial.println(testJson["testE"].as<double>(), 9);
String strTestJson;
Serial.println();
serializeJson(testJson, strTestJson);
Serial.println(strTestJson);
}
Compiler output
No relevant output.
Program output
If relevant, include the repro program output.
Expected output:
e.g.:
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}
0.001403982
0.001043521
0.033841712
0.025639649
0.000292723
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}
Actual output:
ArduinoJson-Version: 7.4.2
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}
0.001403982
0.001043521
0.033841712
0.025639649
0.000292723
{"testA":0.001404,"testB":0.001044,"testC":0.033841712,"testD":0.025639649,"testE":0.000293}
================================================================================
ArduinoJson-Version: 7.2.0
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}
0.001403982
0.001043521
0.033841712
0.025639649
0.000292723
{"testA":0.001404,"testB":0.001044,"testC":0.033841712,"testD":0.025639649,"testE":0.000293}
================================================================================
ArduinoJson-Version: 7.1.0
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}
0.001403982
0.001043521
0.033841712
0.025639649
0.000292723
{"testA":0.001403982,"testB":0.001043521,"testC":0.033841712,"testD":0.025639649,"testE":0.000292723}