Tryining to get float number in scripted filed

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

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 :slightly_smiling_face:

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:

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

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