ARDUINOJSON_USE_DOUBLE
Description
ARDUINOJSON_USE_DOUBLE determines the type used to store floating point values in JsonVariant:
- If
ARDUINOJSON_USE_DOUBLE == 0, thenJsonVariantstores afloat - If
ARDUINOJSON_USE_DOUBLE == 1, thenJsonVariantstores adouble
The default is 0 on embedded systems, 1 otherwise.
Can’t use the Assistant
The ArduinoJson Assistant assumes that your program uses the default value for
ARDUINOJSON_USE_DOUBLE.If you change from the default, the ArduinoJson Assistant will return incorrect values.
Several
.inoor.cppfiles?Be careful if several compilation units compose your program, i.e., if your project contains several
.inoor.cppfiles.It’s crucial that you use the same value of
ARDUINOJSON_USE_DOUBLEin each compilation unit; otherwise, the executable will contain a mix of both versions, and will inevitably crash.
Examples
Example with 32-bit precision
The following program uses 32-bit precision:
#define ARDUINOJSON_USE_DOUBLE 0
#include <ArduinoJson.h>
void example_float()
{
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["pi"] = 3.14159265359;
root.printTo(Serial);
}
It produces the following output:
{"pi":3.141593}
See online demo on wandbox.org
Example with 64-bit precision
The following program uses 64-bit precision:
#define ARDUINOJSON_USE_DOUBLE 1
#include <ArduinoJson.h>
void example_double()
{
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
root["pi"] = 3.14159265359;
root.printTo(Serial);
}
It produces the following output:
{"pi":3.141592654}
See online demo on wandbox.org