# Problem with rounding value of avg calculation

**URL:** <https://discuss.elastic.co/t/problem-with-rounding-value-of-avg-calculation/79036>\
**Category:** Elasticsearch\
**Created:** [March 17, 2017, 2:05pm UTC](https://discuss.elastic.co/t/problem-with-rounding-value-of-avg-calculation/79036 "2017-03-17T14:05:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)\
**Post date:** [March 17, 2017, 2:05pm UTC](https://discuss.elastic.co/t/problem-with-rounding-value-of-avg-calculation/79036/1 "2017-03-17T14:05:54Z")

</div>

Hi,

I call elasticsearch api via curl from a shell script.

Using following aggregation returns sometimes very little values like 8.058358080730823 **e-15**.

```
  "aggs": {
    "1": {
      "avg": {
        "field": "metricsM1"
      }
    }
  }

```

I found some info to use the math functions, but I don't get it running:

```
  "aggs": {
    "1": {
      "avg": {
        "script": "Math.round(doc['metricsM1'].value * 100.0)/100.0"
      }
    }
  }

```

I get following error:

```
{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "Unexpected token VALUE_STRING [script] in [1].",
        "line": 31,
        "col": 19
      }
    ],
    "type": "parsing_exception",
    "reason": "Unexpected token VALUE_STRING [script] in [1].",
    "line": 31,
    "col": 19
  },
  "status": 400
}

```

What is my problem? I just want the precisely calculated average value to be rounded by 2 decimal digits.

I am using elasticsearch 5.1.2.

Thanks, Andreas

---

<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 14, 2017, 2:06pm UTC](https://discuss.elastic.co/t/problem-with-rounding-value-of-avg-calculation/79036/2 "2017-04-14T14:06:15Z")

</div>

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