# Round off a aggregated numeric value to few decimal places

**URL:** <https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316>\
**Category:** Kibana\
**Tags:** kql-kibana-query-language\
**Created:** [October 21, 2021, 1:10pm UTC](https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316 "2021-10-21T13:10:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [October 21, 2021, 1:10pm UTC](https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316/1 "2021-10-21T13:10:04Z")

</div>

Hi Team,

I am aggregating a numeric field which contains the response time data. When i try to find the avg value it is giving me a very long number(\>10 digitis after the decimal point). Could you please help in rounding that value to have two decimal places.

I have tried script with Math.round() function but it is not working. Could you please help me with the query.

I have tried:  
"aggs": {  
"avg\_rtime": {  
"avg": {  
"script": "Math.round(doc['rt.time'].value\*100)/100.0"  
}  
}  
}

o/p:  
{  
"key" : "Data",  
"doc\_count" : 52090,  
"avg\_rtime" : {  
"value" : 193.25108466116336  
}

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [October 21, 2021, 3:12pm UTC](https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316/2 "2021-10-21T15:12:11Z")

</div>

For most places you can specify a formatting for your field in the index pattern: [Manage index pattern data fields | Kibana Guide [7.15] | Elastic](https://www.elastic.co/guide/en/kibana/current/managing-index-patterns.html#field-formatters-numeric)

Can you explain with what kind of visualization you are working? Where do you want to show the average value?

---

<div class="post-metadata">

**Author:** ![venkatkumar229](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatkumar229/32/104663_2.png) [@venkatkumar229](https://discuss.elastic.co/u/venkatkumar229)\
**Post date:** [October 21, 2021, 5:49pm UTC](https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316/3 "2021-10-21T17:49:31Z")

</div>

Hi Joe,

I am using this query to send an email alert using watcher in kibana. I am sending the average values in the email text. So i want to round them to show only two decimal places or one or to a nearest integer.

If there is any chance in rounding the values in the email text body also useful for me.

---

<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:** [November 18, 2021, 5:50pm UTC](https://discuss.elastic.co/t/round-off-a-aggregated-numeric-value-to-few-decimal-places/287316/4 "2021-11-18T17:50:18Z")

</div>

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