# Scripted field - painless converting to float

**URL:** <https://discuss.elastic.co/t/scripted-field-painless-converting-to-float/79671>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 2:40am UTC](https://discuss.elastic.co/t/scripted-field-painless-converting-to-float/79671 "2017-03-23T02:40:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cf\_alister](https://avatars.discourse-cdn.com/v4/letter/c/59ef9b/32.png) [@cf\_alister](https://discuss.elastic.co/u/cf_alister)\
**Post date:** [March 23, 2017, 2:40am UTC](https://discuss.elastic.co/t/scripted-field-painless-converting-to-float/79671/1 "2017-03-23T02:40:44Z")

</div>

Hi, i am trying to get the following to work via kibana in a scripted field but all it causes is errors (not very descriptive), pretty sure this is an elasticsearch misunderstanding so posting it here.

example events [{ 'name': 'Name One', 'cash': 100}, { 'name': 'Name One', 'cash': 24}, { 'name': 'Name Two', 'cash': 112}]

def rtp = ['Name One': 0.986f, 'Name Two': 0.94f];  
def name = doc['name'].value;  
def rtp\_val = rtp[name];

def win\_pct = 1 - rtp\_val; // errors  
def cash = doc['cash'].value;  
def win\_amt = cash \* win\_pct; // errors but mainly due to first one.  
return win\_amt;

Only thing i can think of is that the error is something related to types so looked around trying to find a way to convert to floats, the only example i did end up finding doesn't work and is quite old, pretty sure it's a groovy example.

Float.parseFloat(rtp\_val); // errors

Any one know how to achieve this ?

P.S would be nice to have kibana show an example output from a random event

Thanks

---

<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:** [April 20, 2017, 2:41am UTC](https://discuss.elastic.co/t/scripted-field-painless-converting-to-float/79671/2 "2017-04-20T02:41:08Z")

</div>

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