# Unexpected floating-point precision issue with scaled\_float field

**URL:** <https://discuss.elastic.co/t/unexpected-floating-point-precision-issue-with-scaled-float-field/369865>\
**Category:** Elasticsearch\
**Created:** [October 31, 2024, 7:17am UTC](https://discuss.elastic.co/t/unexpected-floating-point-precision-issue-with-scaled-float-field/369865 "2024-10-31T07:17:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kangquanzhou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kangquanzhou/32/138900_2.png) [@kangquanzhou](https://discuss.elastic.co/u/kangquanzhou)\
**Post date:** [October 31, 2024, 7:17am UTC](https://discuss.elastic.co/t/unexpected-floating-point-precision-issue-with-scaled-float-field/369865/1 "2024-10-31T07:17:04Z")

</div>

**Description** :  
I'm experiencing an unexpected floating-point precision issue when performing aggregations on a `scaled_float` field in Elasticsearch. I have defined a field with `scaled_float` type and a `scaling_factor` of 100. Here are the details:

**Elasticsearch Version** :  
7.14.2

**Index Mapping** :  
{  
"mappings": {  
"properties": {  
"my\_field": {  
"type": "scaled\_float",  
"scaling\_factor": 100  
}  
}  
}  
}

**Sample Data** :  
POST /my\_index/\_doc/1  
{  
"my\_field": 0.1  
}

POST /my\_index/\_doc/2  
{  
"my\_field": 0.2  
}

**Query** : I executed the following aggregation to sum the values of my\_field:  
{  
"aggs": {  
"total": {  
"sum": {  
"field": "my\_field"  
}  
}  
}  
}

**Expected Result** :  
I expected the sum to be 0.3.

**Actual Result** :  
The result returned was 0.30000000000000004.

**Additional Information** :  
This result appears to be a floating-point precision issue, which is common in computer systems.  
I would like to understand why this is happening and if there are any recommended approaches to handle floating-point precision in Elasticsearch.

**Questions** :  
Is there a known issue with floating-point precision when using scaled\_float fields?  
What are the best practices for managing floating-point precision when performing aggregations in Elasticsearch?  
Are there any solutions to round the result to a specific precision?

Thank you for your assistance!
