# Floats getting mangled by JAddNumberToObject

**URL:** <https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975>\
**Category:** Notecard API\
**Created:** [February 22, 2024, 5:49am UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975 "2024-02-22T05:49:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjw\_scion](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@tjw\_scion](https://discuss.blues.com/u/tjw_scion)\
**Post date:** [February 22, 2024, 5:49am UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975/1 "2024-02-22T05:49:47Z")

</div>

Here is my note.add request:

J \*req1 = notecard.newRequest(“note.add”);  
if (req1 != NULL)  
{  
JAddBoolToObject(req1, “sync”, true);  
J \*body = JAddObjectToObject(req1, “body”);  
if (body != NULL)  
{  
JAddNumberToObject(body, “CardTime”, time);  
JAddNumberToObject(body, “CardTemp”, cardTemp);  
JAddNumberToObject(body, “voltage”, voltage);  
JAddNumberToObject(body, “AT”, data.TemperatureC);  
JAddNumberToObject(body, “AH”, data.Humidity);  
JAddNumberToObject(body, “probeTip”, probeTemps[0]);  
JAddNumberToObject(body, “probe30cm”, probeTemps[2]);  
JAddNumberToObject(body, “probe60cm”, probeTemps[3]);  
JAddNumberToObject(body, “probe90cm”, probeTemps[5]);  
JAddNumberToObject(body, “probe120cm”, probeTemps[4]);  
JAddNumberToObject(body, “probe150cm”, probeTemps[1]);  
}  
notecard.sendRequest(req1);  
}

The values for the probe temps are mangled, they should all be around 23 degrees but the output looks like this:

{“req”:“note.add”,“sync”:true,“body”:{“CardTime”:1708580403,“CardTemp”:24.4375,“voltage”:3.538048032501625,“AT”:23.886474609375,“AH”:50.33951187133789,“probeTip”:23.886474609375,“probe30cm”:74.99565124511719,“probe60cm”:0,“probe90cm”:0,“probe120cm”:0,“probe150cm”:50.33951187133789},“crc”:“0032:1DAA93BA”}

---

<div class="post-metadata">

**Author:** ![zfields](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/zfields/32/29_2.png) [@zfields](https://discuss.blues.com/u/zfields)\
**Post date:** [February 23, 2024, 12:18am UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975/2 "2024-02-23T00:18:45Z")

</div>

Hi @tjw_scion, good to see you again!

I’m going to try and reproduce your findings. Can you give me some additional context?

1. How are you defining `probeTemps[]`, I’m assuming it’s `float probeTemps[6]`, but perhaps it’s `double` or something different yet.
2. Have you placed a template on the Notefile?

Thanks,  
Zak

---

<div class="post-metadata">

**Author:** ![tjw\_scion](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@tjw\_scion](https://discuss.blues.com/u/tjw_scion)\
**Post date:** [February 23, 2024, 2:03am UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975/3 "2024-02-23T02:03:22Z")

</div>

Yeah just standard Arduino floats defined like this

`float probeTemps[numberOfDevices];`

I’ll plug away at it and see if I can better define the behaviour.

---

<div class="post-metadata">

**Author:** ![zfields](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/zfields/32/29_2.png) [@zfields](https://discuss.blues.com/u/zfields)\
**Post date:** [February 23, 2024, 11:54am UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975/4 "2024-02-23T11:54:08Z")

</div>

I forgot to ask, what are you using for a host microcontroller, and are you using the latest version of `note-arduino`?

---

<div class="post-metadata">

**Author:** ![zfields](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/zfields/32/29_2.png) [@zfields](https://discuss.blues.com/u/zfields)\
**Post date:** [February 23, 2024, 4:00pm UTC](https://discuss.blues.com/t/floats-getting-mangled-by-jaddnumbertoobject/1975/5 "2024-02-23T16:00:26Z")

</div>

I used the latest version of `note-arduino` and an Arduino Mega (AVR), and I was unable to reproduce your results.

```cpp
    float sensor_readings[5];

    sensor_readings[0] = 1.2345;
    sensor_readings[1] = 12.345;
    sensor_readings[2] = 123.45;
    sensor_readings[3] = 1234.5;
    sensor_readings[4] = 12345;

    if (J *req = notecard.newRequest("note.add"))
    {
        JAddBoolToObject(req, "sync", true);
        if (J *body = JAddObjectToObject(req, "body"))
        {
            JAddNumberToObject(body, "probeTip", sensor_readings[0]);
            JAddNumberToObject(body, "probe30cm", sensor_readings[2]);
            JAddNumberToObject(body, "probe60cm", sensor_readings[3]);
            JAddNumberToObject(body, "probe120cm", sensor_readings[4]);
            JAddNumberToObject(body, "probe150cm", sensor_readings[1]);
            notecard.sendRequest(req);
        }
    }

```

On Notehub:

```json
    "body": {
        "probe120cm": 12345,
        "probe150cm": 12.3450002735104,
        "probe30cm": 123.449996914688,
        "probe60cm": 1234.499999997952,
        "probeTip": 1.234500046979072
    },

```

I also tested it on the Swan (ST), and it worked as well.

Perhaps if you can share which host microcontroller you are using with me, then I can reproduce your error.

~Zak
