When I add a double to json array or object, I get 6 decimal places - right side is loaded with zeros: 1.100000.
Tried using CJSON_CreateNumber and CJSON_CreateDouble but can't figure out a way to set precision. Is there a method available?
Limit precision of double in json object or array
-
- Posts: 90
- Joined: Sun Jul 02, 2017 3:38 am
Re: Limit precision of double in json object or array
It seems you are confusing the precision of a data type with its printed representation.
Re: Limit precision of double in json object or array
Yes, my description was incorrect but I had already shutdown when I posted the issue last night. To clarify the question, is there a method to strip zeros from the data representation?
Re: Limit precision of double in json object or array
Would it be possible to elaborate on the question? I'm not following the notion of what it means to add a "double" to an "array" or "object".
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Limit precision of double in json object or array
Neil,
This is taking me back awhile... I was originally sending a json data array of doubles and wanted to limit the precision - the precision was not the issue but my json ended up with a bunch of zeros following the 1 decimal point.
I just took a quick look at the code and at some point I switched from using json data array to a json object which is where I am still at and the json is formed without trailing zeros.
A background routine I was using could not handle the data array so that is why I made the switch - whether this is what solved the trailing zeros issue or not, I do not remember.
This is taking me back awhile... I was originally sending a json data array of doubles and wanted to limit the precision - the precision was not the issue but my json ended up with a bunch of zeros following the 1 decimal point.
I just took a quick look at the code and at some point I switched from using json data array to a json object which is where I am still at and the json is formed without trailing zeros.
A background routine I was using could not handle the data array so that is why I made the switch - whether this is what solved the trailing zeros issue or not, I do not remember.
Re: Limit precision of double in json object or array
Interesting ... I am sensing correctly, the JSON you were transmitting may have shown up as:
[ 2.000000000000000000000 ]
as opposed to
[ 2.0 ]
as you might have hoped/expected?
Semantically 2.0000000000000000 == 2.0 so it was in fact "working" but was perhaps redundant in its data usage. I think we would have to look at how the JSON was being generated and what (if any) library was being used.
[ 2.000000000000000000000 ]
as opposed to
[ 2.0 ]
as you might have hoped/expected?
Semantically 2.0000000000000000 == 2.0 so it was in fact "working" but was perhaps redundant in its data usage. I think we would have to look at how the JSON was being generated and what (if any) library was being used.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Limit precision of double in json object or array
that is correct. my json looked like [2.100000000, 2.100000000] as opposed to [2.1, 2.1].
I was using the snippets JSON.cpp to build the json and form the string.
I was using the snippets JSON.cpp to build the json and form the string.
Who is online
Users browsing this forum: Bing [Bot] and 83 guests