# Tryining to get float number in scripted filed

**URL:** <https://discuss.elastic.co/t/tryining-to-get-float-number-in-scripted-filed/275895>\
**Category:** Kibana\
**Created:** [June 14, 2021, 7:34pm UTC](https://discuss.elastic.co/t/tryining-to-get-float-number-in-scripted-filed/275895 "2021-06-14T19:34:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dontAskToAsk](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@dontAskToAsk](https://discuss.elastic.co/u/dontAskToAsk)\
**Post date:** [June 14, 2021, 7:34pm UTC](https://discuss.elastic.co/t/tryining-to-get-float-number-in-scripted-filed/275895/1 "2021-06-14T19:34:09Z")

</div>

hey I am tried to run this command in a scripted filed

```auto
if (doc['tunnels_map.rx_stats.counters.packets_lost'].size() != 0 && doc['tunnels_map.rx_stats.counters.packets'].size() != 0)
 {doc['tunnels_map.rx_stats.counters.packets_lost'].value / doc['tunnels_map.rx_stats.counters.packets'].value }

```

when I got the result I got an integer result and I am looking for a float result...  
I am tried to split the fileds to a float variable and it doesn't work also..  
I am looking forward to your response 🙂

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 15, 2021, 7:50am UTC](https://discuss.elastic.co/t/tryining-to-get-float-number-in-scripted-filed/275895/2 "2021-06-15T07:50:36Z")

</div>

`doc['tunnels_map.rx_stats.counters.packets_lost'].value` and ` doc['tunnels_map.rx_stats.counters.packets'].value` are most likely integers - to calculate a ratio you need to cast them to floats:

```auto
(float)doc['tunnels_map.rx_stats.counters.packets_lost'].value / (float)doc['tunnels_map.rx_stats.counters.packets'].value

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 13, 2021, 7:51am UTC](https://discuss.elastic.co/t/tryining-to-get-float-number-in-scripted-filed/275895/3 "2021-07-13T07:51:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
