# Doing math with fields values does not show decimals

**URL:** <https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [February 18, 2019, 8:46pm UTC](https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900 "2019-02-18T20:46:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [February 18, 2019, 8:46pm UTC](https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900/1 "2019-02-18T20:46:37Z")

</div>

Hello,

I am trying to calculate a percentage from two fields which in real life calculator gives a value of 0.332 but using sql queries I am only getting "0" therefore while multiplying with 100 instead of getting 33.2 I am getting 0. Any way I can force it to show the decimals?

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [February 20, 2019, 9:07am UTC](https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900/2 "2019-02-20T09:07:13Z")

</div>

Hi @zozo6015,  
Can you mention the ES version you tested this on and the actual query, please?

Thanks.

---

<div class="post-metadata">

**Author:** ![zozo6015](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zozo6015/32/12117_2.png) [@zozo6015](https://discuss.elastic.co/u/zozo6015)\
**Post date:** [February 20, 2019, 9:58am UTC](https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900/3 "2019-02-20T09:58:22Z")

</div>

I was using elasticsearch 6.6.0.

I came up with this query to convert the INT to FLOAT type and then the result would be the expected.

```
SELECT TRUNCATE(CAST(system.filesystem.free AS float)/CAST(system.filesystem.total AS float), 4) AS Free_percentage from "metricbeat-6.5.1-*" WHERE system.filesystem.free IS NOT null ORDER BY "@timestamp" LIMIT 1
```

---

<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:** [March 20, 2019, 9:58am UTC](https://discuss.elastic.co/t/doing-math-with-fields-values-does-not-show-decimals/168900/4 "2019-03-20T09:58:36Z")

</div>

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