0

I'm using this code:

const size_t bufferSize = JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(7);
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.createObject();
JsonObject& loc = root.createNestedObject("loc");
loc["lat"] = 45.123456;
loc["lng"] = 54.654321;

And I'm getting in the output this:

{"loc":{"lat":45.12346,"lng":54.65432}}

But when I change values to strings ("xx.xxxxxx"), it works normally, just giving me a string instead of a double. Why am I missing that 5 and 1?

dda
  • 6,030
  • 2
  • 25
  • 34
Nicky
  • 87
  • 1
  • 13

1 Answers1

0

You can use the ARDUINOJSON_USE_DOUBLE configuration parameter to allow ArduinoJson to use double instead of float type.

#if ARDUINOJSON_USE_DOUBLE
typedef double Float;
#else
typedef float Float;
#endif

If needed you can get more details about float vs double : What is the difference between float and double?

niavlys
  • 38
  • 1
  • 6