Description

ARDUINOJSON_USE_DOUBLE determines the type used to store floating point values in JsonVariant:

The default value is 1. Setting it to 0 doesn’t reduce memory consumption but can slightly reduce code size.

Only 0 and 1 are valid. Any other value (like false or true) will produce a compilation error.

Several .ino or .cpp files?

Be careful if several compilation units compose your program, i.e., if your project contains several .ino or .cpp files.

You should define the same value of ARDUINOJSON_USE_DOUBLE in each compilation unit; otherwise, the executable will be much bigger because it will contain two variants of the library.

Examples

Example with 32-bit precision

The following program uses 32-bit precision:

#define ARDUINOJSON_USE_DOUBLE 0
#include <ArduinoJson.h>

void example_float()
{
  JsonDocument doc;
  doc["pi"] = 3.14159265359;
  serializeJson(doc, Serial);
}

It produces the following output:

{"pi":3.141593}

Example with 64-bit precision

The following program uses 64-bit precision:

#define ARDUINOJSON_USE_DOUBLE 1
#include <ArduinoJson.h>

void example_double()
{
  JsonDocument doc;
  doc["pi"] = 3.14159265359;
  serializeJson(doc, Serial);
}

It produces the following output:

{"pi":3.141592654}

See also