Round off a aggregated numeric value to few decimal places

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
}

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

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

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.