# Question about precision in Elastic Search, Need to take the values till 18 to 20 decimals

**URL:** <https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531>\
**Category:** Elasticsearch\
**Created:** [March 15, 2019, 1:11pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531 "2019-03-15T13:11:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_gupta1/32/42108_2.png) [@Vishal\_Gupta1](https://discuss.elastic.co/u/Vishal_Gupta1)\
**Post date:** [March 15, 2019, 1:11pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/1 "2019-03-15T13:11:38Z")

</div>

Hi,

I have been using Elastic Search V 6.6.4 for my project from last 6 months or so. However, after completing the product when we are doing the verification of the values , we can see there is a mismatch in values after 15 decimal places. There are some values where we need the values to be saved till 18 or 20 decimal places. We checked that Elastic search is automatically rounding off the values to 15 decimals or so.

We are looking for some immediate answers that is it a functionality or a known bug to ES team or is it already resolved in some previous releases and then we need some help on priority basis to resolve this.

Hope to get a reply asap.

Vishal Gupta  
Bengaluru, India

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 15, 2019, 1:23pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/2 "2019-03-15T13:23:20Z")

</div>

It may be a limitation in Elasticsearch, but it is also possible that this is a limitation in JSON and how floating point values are encoded/decoded. It may therefore depend on which client library/language you use, so some additional information about this could be useful.

---

<div class="post-metadata">

**Author:** ![Vishal\_Gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_gupta1/32/42108_2.png) [@Vishal\_Gupta1](https://discuss.elastic.co/u/Vishal_Gupta1)\
**Post date:** [March 19, 2019, 7:18am UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/3 "2019-03-19T07:18:02Z")

</div>

We are using C#.Net. Let me know which other information is required?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 19, 2019, 11:07am UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/4 "2019-03-19T11:07:46Z")

</div>

The value in the document source is returned to clients exactly as it was received (unless you are using source filtering). However if you are mapping the value as a [numeric datatype](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#number) then, as documented, it will be treated as an IEEE 754 floating point number during searches.

When you say you are "doing the verification of the values", what do you mean?

---

<div class="post-metadata">

**Author:** ![Vishal\_Gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_gupta1/32/42108_2.png) [@Vishal\_Gupta1](https://discuss.elastic.co/u/Vishal_Gupta1)\
**Post date:** [March 19, 2019, 12:26pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/5 "2019-03-19T12:26:05Z")

</div>

Thanks David. In my case Value is a double data type field. Could you tell me what is the max number of decimal digits a double data type can store in ES? Also, if it is 15 then which one i should use so that it does not miss the last few decimals?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 19, 2019, 12:44pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/6 "2019-03-19T12:44:12Z")

</div>

As per [the manual that I linked above](https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html#number), Elasticsearch stores doubles as 64-bit IEEE 754 floating point numbers, giving [53 binary digits of precision](https://en.wikipedia.org/wiki/IEEE_754), which is roughly 15 decimal places. But I still don't understand what "doing the verification of the values" is: Elasticsearch does the same thing as C# here, so I suspect that your verification process might not be doing the right thing.

---

<div class="post-metadata">

**Author:** ![Vishal\_Gupta1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_gupta1/32/42108_2.png) [@Vishal\_Gupta1](https://discuss.elastic.co/u/Vishal_Gupta1)\
**Post date:** [March 19, 2019, 1:15pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/7 "2019-03-19T13:15:35Z")

</div>

In our application, we are storing the account balance of an account holder in Values variable of double data type. We checked that for one of the account holder, C# is sending the account balance similar to -9.909909909118561064 but after saving it into ES, we are getting it as -9.909909909118561... last 3 decimal values are not getting fetched.

Let me know what alternative i can use to avoid this.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [March 19, 2019, 1:55pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/8 "2019-03-19T13:55:16Z")

</div>

> [@Vishal\_Gupta1](#):
>
> C# is sending the account balance similar to -9.909909909118561064

You cannot store numbers to this precision in a `double` variable in C#:

```auto
		double v1 = -9.909909909118561064;
		double v2 = -9.909909909118561;
		Console.WriteLine(String.Format("{0} {0:r} {1} {1:r} {2}", v1, v2, v1 == v2));

```

The output was:

```auto
-9.90990990911856 -9.90990990911856 -9.90990990911856 -9.90990990911856 True

```

I cannot reproduce the problem you are experiencing with the small amount of detail you've given. You will need to describe this "verification" process in much more detail.

---

<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 16, 2019, 1:55pm UTC](https://discuss.elastic.co/t/question-about-precision-in-elastic-search-need-to-take-the-values-till-18-to-20-decimals/172531/9 "2019-04-16T13:55:20Z")

</div>

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