# Scripted field rounds values \<1 to 0

**URL:** <https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420>\
**Category:** Kibana\
**Created:** [July 10, 2018, 7:09pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420 "2018-07-10T19:09:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apatel](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@apatel](https://discuss.elastic.co/u/apatel)\
**Post date:** [July 10, 2018, 7:09pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420/1 "2018-07-10T19:09:20Z")

</div>

I have two fields (px\_last and implied\_price) that I am trying to find the percent difference of using a scripted field in painless. I ran into problems trying to calculate it when I saw I was getting results of 200% deviation, which was being caused by the first field being interpreted as 0 whenever the field was between 0 and 1. Even when I try to simply print the value in a dummy scripted field `price` it rounds to 0:

```
return doc['implied_price'].value;

```

I've checked the mappings and ensured both fields were floats, tried multiplying by 100.0 then dividing by 100.0, and explicitly casting the value to a double, but all yield a value of 0. I also changed the format of the scripted field to show 3-5 decimals places. I'm using Kibana 5.6.8 and Elasticsearch 5.6.9.

Here's an example of an affected row:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/5/952ec41b91c85e6b8d326a21f10c16cdb40701bc.png)

I've tried searching all related issues on the elastic forum and checked the issues on the github repository and couldn't find anything that helped solve my problem, so any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2018, 9:21pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420/2 "2018-07-10T21:21:05Z")

</div>

Can you try storing `px_last` as a `scaled_float`?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2018, 9:40pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420/3 "2018-07-10T21:40:07Z")

</div>

Can you try the following.

In Dev tools, create a simple index pattern and add some documents by running the following

```auto
PUT testindex
{
    "settings" : {
        "index" : {
            "number_of_shards" : 1, 
            "number_of_replicas" : 0
        }
    }
}

PUT testindex/_mapping/_doc 
{
  "properties": {
    "myFloat": {
      "type": "float"
    }
  }
}

PUT testindex/_doc/1
{
    "myFloat" : 0.98604
}

PUT testindex/_doc/2
{
    "myFloat" : 1.9
}

 PUT testindex/_doc/3
{
    "myFloat" : 0.3
}

```

Then create an index pattern for testindex and create a scripted field with the following script `return doc['myFloat'].value;`.

What do you see on Discover? You should see something like this

 ![28%20PM](https://us1.discourse-cdn.com/elastic/original/3X/0/5/05c4606457ca6010ba70175181399206cb1845b3.png)

---

<div class="post-metadata">

**Author:** ![apatel](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@apatel](https://discuss.elastic.co/u/apatel)\
**Post date:** [July 11, 2018, 2:49pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420/4 "2018-07-11T14:49:42Z")

</div>

> [@Nathan\_Reese](#):
>
> return doc['myFloat'].value;

I tried this and it worked, and realized that the rows affected with this problem only come from one day, so I'll see if I can try to re-log those records and see if the problem is fixed

---

<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:** [August 8, 2018, 2:49pm UTC](https://discuss.elastic.co/t/scripted-field-rounds-values-1-to-0/139420/5 "2018-08-08T14:49:43Z")

</div>

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