# Another Payload Decoder Question (issues converting bytes to float)

**URL:** <https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879>\
**Category:** Application Development\
**Created:** [February 7, 2021, 1:51am UTC](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879 "2021-02-07T01:51:18Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![clv](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/clv/32/46568_2.png) [@clv](https://www.thethingsnetwork.org/forum/u/clv)\
**Post date:** [February 12, 2021, 6:22pm UTC](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879/7 "2021-02-12T18:22:25Z")

</div>

1. You probably don’t need 32bits (4bytes) precision but 24 bits (3 bytes). So, you can send 2 bytes less.

In my case it _seems_ ok this:

```auto
// https://github.com/ricaun/esp32-ttnmapper-gps/blob/8d37aa60e96707303ae07ca30366d2982e15b286/esp32-ttnmapper-gps/lmic_Payload.ino#L21
          // accuracy till 5-6 decimal
          lat = ((fix.latitude() + 90) / 180) * 16777215;
          lon = ((fix.longitude() + 180) / 360) * 16777215;
            
            loraData[0] = lat >> 16; // MSB
            loraData[1] = lat >> 8;
            loraData[2] = lat; // LSB

            loraData[3] = lon >> 16;
            loraData[4] = lon >> 8;
            loraData[5] = lon;
```

On decoder (js) TTN V2

```auto
decoded.latitude = +((bytes[0] << 16 | bytes[1] << 8 | bytes[2]) / 16777215.0 * 180.0 - 90).toFixed(6);
decoded.longitude = +((bytes[3] << 16 | bytes[4] << 8 | bytes[5]) / 16777215.0 * 360.0 - 180).toFixed(6);
```

Thanks to: [How to send float value and convert it into bytes - #8 by arjanvanb](https://www.thethingsnetwork.org/forum/t/how-to-send-float-value-and-convert-it-into-bytes/9646/8)

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/another-payload-decoder-question-issues-converting-bytes-to-float/43879)._
