# Field type for decimal values such as 20.5, 10,3 etc?

**URL:** <https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139>\
**Category:** Elasticsearch\
**Created:** [May 22, 2019, 6:33am UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139 "2019-05-22T06:33:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 22, 2019, 6:33am UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139/1 "2019-05-22T06:33:59Z")

</div>

Hi,

What is the best field type to use numerical values such as 20.5, 10,3? For some reason I mapped them as half-float long ago but now I sometimes get values such as 20.5123. At the time this was fine as I used Kibana's formatter to just make them look like x.x again but now I want to give some color formatting to my data.

Also, is there any difference between the field type I should use for 20\*\*. **5 or 20** ,\*\*5?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 24, 2019, 12:33pm UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139/2 "2019-05-24T12:33:15Z")

</div>

I would use a `scaled_float` for exact decimal values. A scaled float is just a `long` internally, that applies a scaling factor to turn it into a decimal for presentation purposes. So you can configure the range of values you care about and keep precision.

The various floats (float, double, half-float, etc) are all true floating-point data types, and you'll see rounding error due to how the floating point math works. Fine for most quantities, but not acceptable for things like currency 🙂

---

<div class="post-metadata">

**Author:** ![Sjaak01](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@Sjaak01](https://discuss.elastic.co/u/Sjaak01)\
**Post date:** [May 27, 2019, 8:05am UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139/3 "2019-05-27T08:05:37Z")

</div>

Thanks.

scaled\_float and scaling\_factor 100 makes x.xx values display correct.

Will updating my template be enough for the new settings to be applied when my index rolls over?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [May 28, 2019, 1:41pm UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139/4 "2019-05-28T13:41:22Z")

</div>

Yep, updating the template should allow all new indices to use the new data type. 🙂

---

<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:** [June 25, 2019, 1:41pm UTC](https://discuss.elastic.co/t/field-type-for-decimal-values-such-as-20-5-10-3-etc/182139/5 "2019-06-25T13:41:29Z")

</div>

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