# If the numbers after the decimal is zero, it doesn't return as a double value?

**URL:** https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515
**Category:** Elasticsearch
**Created:** [November 1, 2016, 5:41am UTC](https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515 "2016-11-01T05:41:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)
#### Post date: [November 1, 2016, 5:41am UTC](https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515/1 "2016-11-01T05:41:23Z")

</div>

I'm having an index created in `elasticsearch 5.0`, where it contains data from my `MySQL` db. There's a field which is a `string` in my table, which I need it as a `double` in ES.

So what I did was added the mapping when I created the index for the appropriate field using a `PUT`:

```
{
  "mappings": {
    "my_type": {
      "properties": {      
        "chargeamount": {
          "type": "double"
        }
      }
    }
  }
}

```

After I did this, a value which contains numbers after the decimal (ie: 23.23) returns the value properly as a double but where as numbers which has zeros after the decimal (ie: 23.00) returns it as a string itself (ie: 2300).

Where am I going wrong? Any help could be appreciated.

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [November 1, 2016, 8:02am UTC](https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515/2 "2016-11-01T08:02:29Z")

</div>

Hi,

What do you mean by "doesn't return a double value"? Can you show us a Put and Get/Search operation with a document that shows the unexpected behaviour? If you mean that if you

```auto
PUT /index/type/1
{ "chargeamount" : "1.56" }

```

your get

```auto
"hits": [
      {
        "_index": "index",
        "_type": "type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "chargeamount": "1.56"
        }
      }, [...]

```

That is to be expected, because Elasticsearch returns the original document exactly as it was entered in the "\_source" field.  
Other than that, with the above mapping your values should be index as doubles.

---

<div class="post-metadata">

### Author: ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)
#### Post date: [November 1, 2016, 8:11am UTC](https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515/3 "2016-11-01T08:11:34Z")

</div>

> [@cbuescher](#):
>
> What do you mean by "doesn't return a double value"? Can you show us a Put and Get/Search operation with a document that shows the unexpected behaviour?

I'm sending a `POST` request as such in order to retrieve data from the index:

**[http://myhostmachine:9402/myindex/\_search?](http://myhostmachine:9402/myindex/_search?)**

And this is what I have in my body:

```
{  
	"size" : 10,
	"_source": ["chargeamount"], 
   "query":{  
      "query_string":{  
         "query":"myquery"
      }
   },
   "aggs":{  
      "total":{  
         "terms":{  
            "field":"user"
         },
         "aggs":{  
            "total":{
               "sum":{  
                   "field": "chargeamount" 
               }
            }
         }
      }
   }
}

```

And the result looks like this:

> **[{ "took": 521, "timed\_out": false, "\_shards": { "total": 5, " -...](https://pastebin.com/he39pU2B)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

At the bottom of the results, you could see the aggs total doesn't return a double 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 5, 2017, 10:07pm UTC](https://discuss.elastic.co/t/if-the-numbers-after-the-decimal-is-zero-it-doesnt-return-as-a-double-value/64515/4 "2017-07-05T22:07:58Z")

</div>


